Clear Filters
Clear Filters

Large format spec statement in textscan

4 views (last 30 days)
Aaron Smith
Aaron Smith on 15 Feb 2017
Commented: Stephen23 on 15 Feb 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 Comments
Stephen23
Stephen23 on 15 Feb 2017
Edited: Stephen23 on 15 Feb 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.

Sign in to comment.

Answers (1)

dpb
dpb on 15 Feb 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 Comments
Aaron Smith
Aaron Smith on 15 Feb 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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!