I have a function that returns one or more variables, but as it changes (depending on whether this function is successful or not), the following does NOT work:
[resultA, resultB, resultC, resultD, resultE, resultF] = func(somevars);
This sometimes returns an error, varargout {2} is undefined, since only the first variable resultAactually gets the value when the function fails. Instead, I put all the output in a single variable:
output = func(somevars);
However, variables are defined as properties of the structure, that is, I have to access them using output.A. This is not a problem in itself, but I need to count the number of properties to determine if I got the correct result.
I tried length(output), numel(output)and to size(output)no avail, so if anyone has a smart way to do this, I would be very grateful.
source
share