How do I change the name of a variable (actually value of a character array) inside a loop?

12 visualizzazioni (ultimi 30 giorni)
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
Adrian Barbu
Adrian Barbu il 20 Apr 2023
Modificato: Adrian Barbu il 20 Apr 2023
Hi Matt,
Thank for the heads up. I understand why it is not a good idea, but the toolbox I am using is limited. I can not implement those sugestions.
mi_setnodeprop('Current',count_slot);
This is the only line I can edit. The first value, "Current" is the name I want to edit, the second is the group number, a concept specific to the toolbox used to create an interface with a different software.
I do not see any oher solution then to edit the name while in the loop. If you have any idea, it would be amazing.
Again, thank you for your time.
Stephen23
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.

Accedi per commentare.

Risposta accettata

Stephen23
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
T = 'Current1'
T = 'Current2'
T = 'Current3'
T = 'Current4'
T = 'Current5'
for k = 1:5
T = "Current"+k % string scalar
end
T = "Current1"
T = "Current2"
T = "Current3"
T = "Current4"
T = "Current5"
"I am unable to find any information on this."

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by