How to create a variable named from string
Ältere Kommentare anzeigen
I'm loading data from an excel file, with multiple objects. I want to create a variable (matrix) named after the object, containing processed data.
So this is basically what I have:
test_data.name(i) = 'Object 2-1'
This is what i want:
Object_2_1 = [3 4 5 etc.];
This means i both needs to replace "space" and "-" with "_" and then name/create the variable. Can someone please help me on how to approach this challenge?
4 Kommentare
Kasper Buchardt
am 3 Dez. 2020
Deepak Gupta
am 3 Dez. 2020
You can refer this page: https://in.mathworks.com/help/matlab/ref/genvarname.html
Stephen23
am 3 Dez. 2020
You can also refer to this page: https://www.mathworks.com/help/matlab/matlab_prog/string-evaluation.html
which states "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended. The preferred method is to store related data in a single array."
and also this page, which gives plenty of reaons why this approach to writing code should be avoided:
Kasper Buchardt
am 3 Dez. 2020
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu MATLAB 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!