Varying parameters in if statement
Afficher commentaires plus anciens
Hi! I would like to create a conditional statement where the parameters of my if statement is changing. Is it possible to vary the parameters in the if statement?
Here is an example:
x10=1;
i=10;
word='x';
if ('%s%d~=1',word,i)
v='not working'
end
I tried this one but it is not working, any suggestion on how to make it work?
Réponse acceptée
Plus de réponses (1)
Mischa Kim
le 9 Mar 2014
Modifié(e) : Mischa Kim
le 9 Mar 2014
Something like:
mynum = 2; % change to mynum = 1
x10 = 1;
word = 'x';
i = 10;
if (eval(genvarname(strcat(word,num2str(i)))) == mynum)
fprintf('x10 is %d\n', mynum);
else
fprintf('x10 is not %d\n', mynum);
end
1 commentaire
ericson
le 9 Mar 2014
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!