Another option is to use assignin to automatically save the output argument to the workspace.
function [ A, B, C ] = test(x, y, z) A=2*x; B=2*y; C=2*z; assignin('base', 'A', A); assignin('base', 'B', B); assignin('base', 'C', C); end
'base' is the name of the main workspace used when invoking variables from the command window.
So you can enter test(x,y,z) into the workspace without the [A,B,C] = , and it will still give you all the values.
The advantage of this when combing A, B and C into one conclusion is that you still have 3 separate variables stored in your work area. This is useful if A, B, and C are arrays or cells. The disadvantage of this method is that if you use this function inside another function, it will only use the value A. For example: length(test(x,y,z)) will simply indicate the length of A.
Blue7
source share