load text file

6 visualizaciones (últimos 30 días)
Baba
Baba el 3 de Nov. de 2011
I have a text file that is too large to load with the file=load'file.txt' command. it's basically many rows of numbers where each column separated by a space.
1 2 3 1 4 2 1 56 2....
1 4 1 56 2 3 4 2 3 ....
....
Each row contains data from several channels. So for instance data from channel 1 would be 1 2 3 1 4 1, first 3 numbers of every line:
What I'd like to do is to filter and downsample data from each channel.
so basically I'm wondering what command is best to use to pick out specific parts of text file without using "load"
  1 comentario
Fangjun Jiang
Fangjun Jiang el 3 de Nov. de 2011
How large is the file? How many rows and columns?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Nov. de 2011
samplesperchan = 3;
channelnum = 6; %for example
lineformat = [repmat('%*f', 1, samplesperchan*(channelnum-1)), repmat('%f',1,samplesperchan), '%*[^\n]'];
result = textscan(fid, lineformat, 'CollectOutput', 1);
  8 comentarios
Baba
Baba el 3 de Nov. de 2011
I'm getting an error:
??? Error using ==> textscan
Buffer overflow (bufsize = 4095) while reading string from
file (row 1, field 10). Use 'bufsize' option. See HELP
TEXTSCAN.
Error in ==> Untitled5 at 8
result = textscan(fid, lineformat, 'CollectOutput', 1);
and buffsize maximum size is 4095 bytes
is there a workaround that you know of?
Walter Roberson
Walter Roberson el 4 de Nov. de 2011
It sounds as if you might need to use 'bufsize' with a large number -- as large as your longest line.

Iniciar sesión para comentar.

Más respuestas (1)

Ora Zyto
Ora Zyto el 3 de Nov. de 2011
Depending on the format of your data, TEXTSCAN may be a good option. This is a very flexible function, where you can specify the format of your data programatically.
You could read lines one by one and parse the data directly. If your data is rectangular, you could also try reading it all at once.
Ora
  1 comentario
Baba
Baba el 3 de Nov. de 2011
Thank you

Iniciar sesión para comentar.

Categorías

Más información sobre Text Analytics Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by