Function outputs a 1x2 matrix, yet I can't append that matrix to another matrix.

6 Ansichten (letzte 30 Tage)
function prop(f,u,q,sq)
%Define stuff
SQ=[];
Q=[];
g=size(q);
%Evaluation of f with q
Q=subs(f,u,q);
%Uncertainty
for h=1:g(1,2);
Sq=subs(((diff(f,u(1,h)))^2*sq(1,h)^2),u,q);
SQ=sqrt(sum([SQ Sq]));
end
[Q SQ]
end
The function requires for f a symbolic function, u a row vector with all the variables being used in f, q a row vector that contains values for these variables and sq also some values. (so a symbolic function with n variables and then three 1 x n row vectors). For example f=u1+u2, u=[u1 u2], q=[1 2] and sq=[0.1 0.2].
It outputs a 1x2 matrix, yet when I try
A=[]
A=[A prop(f,u,[1 2],[0.1 0.2])]
I get "??? Error using ==> prop Too many output arguments."
How can I fix this? I need the output of this function to be used in another function which uses this function multiple times for varying q vectors (and then adding the varying output 1x2 vectors to one big vector)

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 26 Nov. 2011
You need to change the first line to:
function A = prop(f,u,q,sq)
and the second to last line to
A = [Q SQ]
You can use any name you want for A.
Depending on what Q and SQ are (potentially they are symbolic), then you may need to initialize A to be something else in your main script
A = sym.empty(0, 2);

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by