I am working on a large data project that has potentially thousands of similarly named files in CSV format that I need to analyze in matlab. These files are named nnnwavex.csv (where nnn = a number and x = either I II III or V).
Ex Directory Contents
- 352waveI.csv
- 352waveII.csv
- 352waveIII.csv
- 352waveV.csv
My previous code to import this was to enter the following
wave352i = importdata('352waveI.csv');tele352i = wave352i.data;text352i = wave352i.textdata;wave352ii = importdata('352waveII.csv');tele352ii = wave352ii.data;text352ii = wave352ii.textdata;wave352iii = importdata('352waveIII.csv');tele352iii = wave352iii.data;text352iii = wave352iii.textdata;wave352v = importdata('352waveV.csv');tele352v = wave352v.data;text352v = wave352v.textdata;
Now I have generated a bit of variable naming code that seems to work well for the first part (importing the file as a struct of data and textdata). I have spent hours reading the material about why variable naming is not ideal. This is simply to import large numbers of files quickly.
x=352;y='wave';z='I'a='.csv'b='tele'c='.data'cat(2,num2str(x),y,z,a)eval(['temp = importdata(ans)']);cat(2,y,int2str(x),z);v = genvarname(ans);eval([v '= temp']);z='II'cat(2,num2str(x),y,z,a)eval(['temp = importdata(ans)']);cat(2,y,int2str(x),z);v = genvarname(ans);eval([v '= temp']);z='III'cat(2,num2str(x),y,z,a)eval(['temp = importdata(ans)']);cat(2,y,int2str(x),z);v = genvarname(ans);eval([v '= temp']);z='V'cat(2,num2str(x),y,z,a)eval(['temp = importdata(ans)']);cat(2,y,int2str(x),z);v = genvarname(ans);eval([v '= temp']);clear x y z v temp c b ans a
This leaves me with four struct files
- wave352I
- wave352II
- wave352III
- wave352V
how can I make a script that can then build a variable name that accomplishes the following & gives me a double and a cell from the original struct?
If I create a string a = 'wave352V.data', I cannot use it in my code to call that subset of the struct and apply it to a new variable.
tele352v = wave352v.data;text352v = wave352v.textdata;
I could use excel and word and build a script that uses mail merge to create multiple iterations of the initial code I demonstrated above, but that seems like a very amateur way to approach this.
Any ideas would be appreciated!
Best Answer