0
votes

I have an array which I read into Matlab with importdata. It has 5 header lines

file = 'aoao.csv';
s = importdata(file,',', 5);

Matlab automatically treats the last line as the column header. I can then call up the column number that I want with
s.data(:,n); %n is desired column number

I want to be able to load up many similar files at once, and then call up the columns in the different files which have the same column header name (which are not necessarily the same column number). I want to be able to write and export all of these columns together into a new matrix, preferably with each column labelled with its file name,

what should I do?

1

1 Answers

0
votes
samp = 'len-c.mp3'; %# define desired sample/column header name  

file = dir('*.csv');

have the directory ready in main screen current folder. This creates a detailed description of file,

for i=1:length(file)  
    set(i) = importdata(file(i).name,',', 5);   
end  

this imports the data from each of the files (comma delimited, 5 header lines) and transports it to a cell array called 'set'

for k = 1:14;  
    for i=1:length(set(k).colheaders)  
        TF = strcmp(set(k).colheaders(i),samp); %compares strings for match  
        if TF == 1; %if match is true  
        group(:,k) = set(k).data(:,i); %save matching column# to 'group'  
        end  
    end  
end  

this retrieves the data from the named colheader within each file