0

let us suppose that we have following function

function [y1,y2,y3,y4]=mystery(a,x);
y1=a*x;
y2=a*x^2;
y3=a^2*x^2;

y4=a*x^3+5;
end

now what i want to make sure is order of result returned from this code,for instance

[y1,y2,y3,y4]=mystery(3,5);

does it return in reverse order or directly in direct form?i meant when m file is executed does it first return last result,then previous of last line and so on?thanks in advance

1
  • yes of course,sometimes it may matters Commented Mar 21, 2014 at 9:22

2 Answers 2

2

The parameters are always returned in the order of the declaration. The order of evalutation does not matter. So, in your case, you will always have the order [y1,y2,y3,y4].

Edit: If you want to access the second or third parameter only, you can do [~,y2]=mystery(1,2) or [~,~,y2]=mystery(1,2) respectively.

Sign up to request clarification or add additional context in comments.

2 Comments

if i write [a]=mystery(3,5) it will return y1?
@datodatuashvili Why not try it yourself and see? Try to explore.
1

Matlab executes line by line in the script. The first line is always executed first.

3 Comments

yes but when i write [y1]=mystery(3,5) first line would be returned?
@datodatuashvili Not first line, just the value of y1.
The first line of the function is the function signature. It is seen at first for inputs and at the very end for outputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.