Large format spec statement in textscan
3 次查看(过去 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
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.
Stephen23
2017-2-15
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!