How do I change the name of a variable (actually value of a character array) inside a loop?
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Adrian Barbu
il 20 Apr 2023
Modificato: Image Analyst
il 20 Apr 2023
Hello.
I have the following code:
for count_slot= 1:1:Np
number = count_slot;
.......
mi_addpointprop('Current',0,Ip_theta_real);
mi_selectgroup(count_slot);
mi_setnodeprop('Current',count_slot);
mi_clearselected;
-------------------------------------------------
I want ,for every loop that takes place, to change the name of "Current" to " Current + the number of the loop". I am unable to find any information on this.
Thank you very much for any guidance!
3 Commenti
Stephen23
il 20 Apr 2023
"I understand why it is not a good idea"
What you described is a perfectly good idea, and is very commonly done.
It is just that in MATLAB the term "variable" has a totally different meaning to how you used it.
Risposta accettata
Stephen23
il 20 Apr 2023
Modificato: Stephen23
il 20 Apr 2023
"I do not see any oher solution then to edit the name while in the loop."
What you are asking is just to change some text. This is completely unrelated to changing the name of a variable.
for k = 1:5
T = sprintf('Current%d',k) % character vector
end
for k = 1:5
T = "Current"+k % string scalar
end
"I am unable to find any information on this."
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!