Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

pass arguments to a function that have not been defined in the workspace

1 vue (au cours des 30 derniers jours)
Aneesh Vasudev
Aneesh Vasudev le 15 Juin 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi all,
What am I supposed to do in order to achieve the following:
function op=Mset(op,ip,kk,n)
if kk==1
op=ip./n;
else
op = op + (ip./n);
end
Simply, I would like to pass 'op' which is an undefined variable to the function. In other words, op merely represents a bunch of characters or the name of the variable.
  3 commentaires
Stephen23
Stephen23 le 15 Juin 2018
"In other words, op merely represents ... the name of the variable."
Don't do this. Dynamically accessing variables names is how beginners force themselves into writing slow, complex, buggy code. Read this to know why:
It is much more efficient to use indexing, fieldnames, or the columns/rows of a table.
Aneesh Vasudev
Aneesh Vasudev le 19 Juin 2018
Thanks Stephen and Adam. I'm currently using a struct. I initialized the struct before calling the function and then pass the names of fields and dynamically append it to the struct.

Réponses (0)

Cette question est clôturée.

Produits


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by