Create variable named from a cell
Ältere Kommentare anzeigen
How do I generate a variable of empty matrix, which is named after the values in one of the cell of imported text in another variable.
E.g I import data file with
A {'DT140906' 'x'};
Now I want to create a varible that will automatically take the name 'DT140906' or what ever the name is in A.
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 22 Sep. 2014
0 Stimmen
I think that's a bad idea http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
And how are you going to be able to refer to that variable later in your code when you don't know the name of it until run-time ? You can use dynamic field names in structures but I don't even like that approach.
2 Kommentare
the cyclist
am 22 Sep. 2014
I was going to wait until the expected "that doesn't work" or rarer "thanks!" before I launched into the fact that what you are doing is likely a bad programming practice, but I agree with Image Analyst here.
If you have any control of how these variables are named upstream from your program, you might be able to do better in the MATLAB section of what you are doing. We'd need to know more detail to help you figure out a strategy.
Mandeep
am 22 Sep. 2014
Kategorien
Mehr zu Variables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!