Large format spec statement in textscan

4 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2017-2-15
编辑:Stephen23 2017-2-15
@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.

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2017-2-15
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 个评论
Aaron Smith
Aaron Smith 2017-2-15
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by