Importing multiple files as doubles
Show older comments
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!
Answers (1)
Walter Roberson
on 12 Dec 2013
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};
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!