Possible Duplicate:
how to compare array with matlab
Here’s an example of what I’m looking for:
[a,b,c,d] = getVal(x);
This will give:
a =
a
b=
0
c =
10
d =
[]
And I have:
expected = {'a','0','10',[]};
How could I make the comparison between [a,b,c,d] and expected ?
When I call only getVal(x), it gives me only the first value and when I write:
[a,b,c,d] = getVal(x)
Then I got all values in the log. Why isn’t this the case when I call
getVal(x)?
For comparison I tried:
isequal([a,b,c,d], expected {1:end})
but it doesn’t work, any idea how to solve my problem?
Don’t try to put
a,b,c,dinto a matrix. That would append spaces. Instead, use a cell array, just like you have forexpected:You also asked why simply calling
getVal(x)doesn’t give all the values. That is because in MATLAB, a function can (and often does) react to the number of output parameters, i.e., the number of variables on the left hand side of the assignment. YourgetValfunction returns four values if called with four output parameters; If it doesn’t do anything special, then calling it with zero or one output parameter will return only the first of these values, in your example,'a'. If you want a cell array with all four of these values, do something like