Print String Names to be used for Variable Names?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Thomas Blackwood
Thomas Blackwood il 2 Giu 2017
Ah, so just assign all my values into one mega matrix with size(fileArray) number of columns?
Stephen23
Stephen23 il 2 Giu 2017
Modificato: Stephen23 il 2 Giu 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.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by