Importing multiple files as doubles
显示 更早的评论
I want to import multiple files at the same time. The files are tab delimited and there are 23 text headerlines. I'm having two problems: 1. I can't figure out how to import only the data part of the file (without textdata). I want the imported file to be a double, not a struct. 2. I don't know how to import multiple files.
The code I've tried so far is:
For question 1:
Trial36=dlmread('Trial36','\t',[23 length('Trial36')])
??? Attempted to access range(3); index
out of bounds because numel(range)=2.
Error in ==> dlmread at 99 nrows = range(3) - range(1) + 1;
How do I tell dlmread to read from the 24th row to the last?
For question 2:
for i=1:60
Trial(i)=importdata('Trial(i)','\t',23)
end
??? Error using ==> importdata at 136
Unable to open file.
I'm pretty sure that's because I'm not calling the files correctly. Any advice?
I'd like to integrate both these ideas into one code.
Thanks!
回答(1 个)
Walter Roberson
2013-12-12
Are you aware that length('Trial36') is asking for the length of the literal string, and so would be 7 (7 characters in 'T' 'r' 'i' 'a' 'l' '3' '6') ?
I suggest you use textscan instead of dlmread()
cols_per_row = 18; %change to actual number of columns
fmt = repmat('%f', 1, cols_per_row);
fid = fopen('Tria36', 'r');
datacell = textscan(fid, fmt, 'HeaderLines', 23, 'CollectOutput', true);
fclose(fid);
Trial36 = datacell{1};
类别
在 帮助中心 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!