How to continue execution of textscan if it cannot match formatSpec to the data
1 view (last 30 days)
Show older comments
34,35,36,
34,35,36,37,
34,35,36,
Let say I have the above 3 lines of data which I am reading using textscan. Let say textscan's formatSpec is '%d %d %d'. Then in this case it stops after 1st data line. So I would like to implement a script which continues with another formatSpec if textscan couldn't match initial formatSpec. How can I do it? The logic is below.
fmt_one = '%d %d %d';
fmt_one = '%d %d %d %d';
C = textscan(fileID,'%d %d %d');
if textscan stopped
C = textscan(fileID,'%d %d %d %d');
0 Comments
Answers (1)
Star Strider
on 7 Jun 2015
I would use:
C = textscan(fileID,'%d %d %d %d');
adding the appropriate 'Delimiter', 'CollectOutput', 'EndOfLine' and other name-value pairs as required. If textscan encounters a blank space, it should substitute NaN for the missing value.
0 Comments
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!