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!

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de Dic. de 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};

2 comentarios

Rachel
Rachel el 13 de Dic. de 2013
That makes sense. I was wondering why it was telling me that the length was 7. The code works great. Thanks! I implemented processing multiple files but I'm not sure how to save them under different names. Here's what I have so far.
for i=1:last
cols_per_row = 9;
fmt = repmat('%f', 1, cols_per_row); %create matrix
filename = ['Trial' num2str(i)];
fid = fopen('filename', 'r');
datacell = textscan(fid, fmt, 'HeaderLines', 23, 'CollectOutput', true);
fclose(fid);
['Trial' num2str(i)] = datacell{1};
end
I thought that I could name the saved file in the same way I called a file to read but it gives the error ??? Error: File: LoadBreathAlertData.m Line: 9 Column: 6 An array for multiple LHS assignment cannot contain character string.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Analysis en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Dic. de 2013

Comentada:

el 13 de Dic. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by