Getting variables name from char array
Show older comments
assuming I have a char array like x
a1=[1 2 3 4];
a2=[10 11 15 11];
b2=[4 5 6 7];
c2=[8 9 10 11];
x=['a1' 'a2' 'b2' 'c2']
assuming I have data like this, how can I make the char in x be treated like the variable name meaning that ('a1' --> a1 == [1 2 3 4])
Notes: - All the variables are created before the char array
- I have to name the variables like (a1,a2,..etc.)
-I have a large number of variables
Accepted Answer
More Answers (1)
Simon Philipp Hehenberger
on 11 May 2020
Create a struct for your data.
You can dynamically create fields in your struct with
For example:
for ii=1:4
samplestruct.(['a' num2str(ii)])=fielddata;
end
creates four fields in the struct 'samplestruct', named 'a1',..,'a4'.
Categories
Find more on Structures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!