@G A: using a structure is also good approach. Which approach to use depends on many things, you will have to find the right balance/optimum for your project and needs, e.g.:
structure:
useful when you have many arrays (e.g. more than 6 or 7) which easily lead to confusion when supplied as positional input arguments (we regularly get questions on this topic).
might be easier to process when those arrays are optional
input arguments:
(partially) self-documentating names
pop-up help in the Editor, etc.
I am sure that other users on this forum can add other benefits or considerations.
Thanks, Stephen! One question: what is the main difficulty to make (or reason not to make) it possible in the Editor to higlight structure name with its field throughout a function like it occurs with simple variables when you click on it or select it? Is this question to go to "What frustrates you about Matlab"?
"what is the main difficulty to make (or reason not to make) it possible in the Editor to higlight structure name with its field throughout a function like it occurs with simple variables when you click on it or select it?"
You have to consider that variables in MATLAB are dynamically typed. In general it is difficult to determine the type of a variable until runtime (e.g. changes to function scoping, variables created dynamically, inputs are not typed, etc.)
How would you apply your idea to the non-anonimous functions with different number of input arguments which must be passed within for-loop? The other question is: when a = 0, will Matlab execute function f2 to multiply its return by 0 or, seeing that one term is 0, it will return 0 without execution of f2?
Hm. Not finding a good way to handle this that does not potentially result in empty, Inf, or NaN when one of the functions does not have all the arguments. For example, you could pass zeros into the function when they are not needed, but it is potentially hazardous:
Also, it is time consuming if two functions are executed instead of one. Better to put if-statement into a loop. I have half of answer to my question in my comment above: 0*inf = NaN, 0*A = 0, so to give the answer 0 or NaN, Matlab must execute f2 before multipliing its return by 0.