@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.
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Translated by
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.