Hi all,
Imagine there is a function with many inputs and outputs, according to my knowledge there are two ways to design this function:
Method_1. explicitly write all inputs and outputs:
function [otpt_b1, otpt_b2, ...
some operations
Method_2. use struct as inputs and outputs, i.e.
inpt = struct('a1', 'a2',...
otpt = struct('b1', 'b2', ...
function [otpt] = test(inpt)
some operations
Method_1 is reusable for different inputs, as long as one knows the corresponding location of inputs. For example, this will work:
Method_2 is much more readable, especially when number of outputs and inputs are large. However, one cannot change the content of struct input (the function can only recognise inpt.a1, inpt.a2, etc.), for example, this won't work:
inpt = struct('x1', 'x2', ...
otpt = struct('y1', 'y2', ...
[otpt] = test(inpt)
My question is: what if I want the function to be reusable and readable, i.e. I'd like to use struct as input and output, is there a way to combine advantages of both method_1 and method_2?
Thank you!