[Scilab-users] varargout doubt
Rafael Guerra
jrafaelbguerra at hotmail.com
Tue Nov 8 17:08:18 CET 2016
Please check the two examples here below:
///// START OF CODE
clear;
x=[1 2 3;4 5 6];
y=[4 5 6;7 8 9];
z=10;
M=list(x,y,z);
function out_list=func1(M) //ex.1
n = length(M); // decide the number of variables to output based on function input
out_list = list(1:n);
for i=1:n
out_list(i)=rand(M(i));
end
endfunction
function out_list=func2(x,n) //ex.2
out_list = list(1:n);
for i=1:n
out_list(i)=x.^i;
end
endfunction
Q = func1(M); // Q is a list with same size as input M
n = 5;
P = func2(x,n); // P is a list of matrices with P(i) = X^i, i=1..n
///// END OF CODE
Rgds,
Rafael
-----Original Message-----
From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of shamikam
Sent: Tuesday, November 08, 2016 3:28 PM
To: users at lists.scilab.org
Subject: Re: [Scilab-users] varargout doubt
Thanks for your reply but that didn't work. I would like to illustrate with a
simple example-
function varargout_list=exampl()
[lhs,rhs]=argn(0);
varargout_list = list(1:lhs);
for i=1:lhs
varargout_list(i)=list(ex())
end
endfunction
function [x,y,z]=ex()
x=[1 2 3;4 5 6];
y=[4 5 6;7 8 9];
z=10;
endfunction
exampl() calls ex(). If I call exampl() with more than one o/p argument,
there is an error
-->[c,d,e]=exampl()
!--error 59
Wrong number of output arguments.
-->[c,d]=exampl()
!--error 59
Wrong number of output arguments.
-->c=exampl()
c =
c(1)
1. 2. 3.
4. 5. 6.
If I change varargout_list to varargout like this
function varargout=exampl()
varargout=list(ex())
endfunction
and call exampl(), I get the following errors-
-->[c,d,e]=exampl()
!--error 21
Invalid index.
-->[c,d]=exampl()
!--error 21
Invalid index.
-->c=exampl()
c =
1. 2. 3.
4. 5. 6.
How can I get varargout to work for any number of o/p arguments?
More information about the users
mailing list