开发者

Matlab: finding/writing data from mutliple files by column header text

开发者 https://www.devze.com 2023-03-23 06:30 出处:网络
I have an array which I read into Matlab with importdata. It has 5 header lines file = \'aoa开发者_开发技巧o.csv\';

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

file = 'aoa开发者_开发技巧o.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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号