Print String Names to be used for Variable Names?
1 view (last 30 days)
Show older comments
I have a function that lists filenames in a vertical array of strings.
fileArray = {'file1'
'file2'
'file3'}
Say I want to assign values and have the variable titled file2. I was thinking one could do it like:
disp(fileArray{2}) = 7
to make:
file2 = 7
But this doesn't seem to work. Any alternative suggestions?
3 Comments
Stephen23
on 2 Jun 2017
Edited: Stephen23
on 2 Jun 2017
Sure. Use a numeric matrix, if that works for your data. Else consider a numeric ND array, or a cell array, or a table, or a structure, or...
Accessing and processing data in one array is going to be a lot simpler than trying to do the same with lots of separate variables. As a general rule of thumb keep your data together as much as possible and your code will be much simplified.
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!