Reading multiple .csv files into Matlab while organizing them into new matrices -


i have lots of .csv files want read matlab, doing organization along way

my first problem data looks this:

[...  file1   ex1   6;0   8;0   9;1   file1   ex2   7;0   8;1   3;2   file1   ex3   7;0   8;1   3;2   

the import wizard on matlab reason takes first header text data set below , throws away when reaches next text header. how can organize file looks instead?

[...  file1......file1.....file1   ex1.......ex2.......ex3   6;0.......7;0.......7;0   8;0.......8;1.......8;1   9;1.......3;2.......3;2   

note: number of rows different ex's different, can't spilt file regular chunks.

my second problem compare same experiments different files. want take columns below "ex1" different files , line horizontally against each other in new matrix. looks this:

file1.....file2.....file3.....     ex1.......ex1.......ex1.......     6;0.......6;0.......6;0.......   8;0.......8;0.......8;0.......   9;1.......9;1.......9;1.......  

note: ex's in different files in different orders. need match ex's within files based on matching 1 of lines of header (e.g. whenever called 'track1').


edit:

this how actual data looks like.

since number of rows in each ex different, must use cell matrix.

file = 'file1.csv'; h = 2; % # header lines num_ex = 3; r = h; % track current row in file data = cell(1,num_ex); i=1:num_ex     s = importdata(file, ';', r);     x = s.data;     data{i} = x;     r = r + size(x,1) + h; end 

then can access data using curly bracket cell matrix notation

ex = 2; x = data{ex}; 

so get

x = [ 7  0       8  1       3  2 ] 

for second problem, can add loop go through each file

filenames = {'file1.csv', 'file2.csv', 'file3.csv'}; h = 2; % # header lines num_ex = 3; r = h; % track current row in file data = cell(1,num_ex); i=1:num_ex     f=1:length(filenames)         file = filenames{f};         s = importdata(file, ';', r);         x = s.data;         data{i} = [data{i} x];     end     r = r + size(x,1) + h; end 

so data{1} has data ex 1, etc.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -