Create a variable from string

34 Ansichten (letzte 30 Tage)
Matt
Matt am 1 Sep. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019
Hello!
In my Matlab program, I have a class named "time". In this class I have a variable named "car". in a FOR loop, I am adding coefficients to this variable which gives me "car1", "car2", "car3". But I want these variables to remain in the "time" class.
How can I do it? I used to have something like this before creating the "time" class:
assignin('base', ['car' num2str(count+1)], somevalue);
This would give me the variables "car1", "car2", and so on, depending on the "count" variable. But how can I make the "time.car1", "time.car2", "time.car3" variables? ASSIGNIN doesn't accept classes in the variable name.
Thanks in advance!
  1 Kommentar
Stephen23
Stephen23 am 1 Sep. 2015
Bearbeitet: Stephen23 am 1 Sep. 2015
You should never include pseudo indices in variable names. Just use one variable and actual indices instead, in a numeric, cell or structure array. Here are some discussions that explain why this is a bad idea:

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 1 Sep. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by