Borrar filtros
Borrar filtros

Large format spec statement in textscan

4 visualizaciones (últimos 30 días)
Aaron Smith
Aaron Smith el 15 de Feb. de 2017
Comentada: Stephen23 el 15 de Feb. de 2017
I have a very large matrix file that I am trying to textscan and reform into blocks of equal size. The matrix is 51200 rows of 1025 integers each separated by semicolons and I am attempting to create 50 blocks of 1024 x 1025. My question was, because my rows of data contain 1025 integers, I can not write '%d %d %d %d %d....' 1025 times. Is there a way to state that there are 1025 integers (for example '1025*%d'). Also, Is there a way to command my desired reformatting of the data into blocks in the textscan line?
  2 comentarios
Stephen23
Stephen23 el 15 de Feb. de 2017
Editada: Stephen23 el 15 de Feb. de 2017
@Aaron Smith: when you ask questions that are very closely related to other questions, it helps us a lot if you put a link to the other questions. This means we can check what information you have already been given, and avoids pointless and annoying repetition of the same questions and topics.

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 15 de Feb. de 2017
fmt=repmat('%d',1,1025);
data=textscan(fid,fmt,...
For the second, use the option N multiplier to control the number of times the format statement is applied and enclose the textscan call in a loop. Each block can be a cell array element as one choice or can process and discard if the algorithm lends itself to that.
There's one handy 'trick' with textscan which is to use an empty string for the format string and it will automagically determine the record size and return the array in the shape of the file storage. Then you can reshape or mat2cell as desired.
  2 comentarios
Aaron Smith
Aaron Smith el 15 de Feb. de 2017
What type of loop would work for this purpose? While ~feof()? I'm not sure how to format the loop with the N multiplier. Also using while~feof has caused problems in the past for me with an error (invalid file identifier) arising. Any clarification you can provide would be greatly appreciated as you initial answer is.
Stephen23
Stephen23 el 15 de Feb. de 2017
Editada: Stephen23 el 15 de Feb. de 2017

Iniciar sesión para comentar.

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by