Print String Names to be used for Variable Names?

1 view (last 30 days)
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
Thomas Blackwood
Thomas Blackwood on 2 Jun 2017
Ah, so just assign all my values into one mega matrix with size(fileArray) number of columns?
Stephen23
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!