How can I display the progress of textscan
Show older comments
I am using textscan to read and parse data files that vary widely in size. For small files it is very fast, but it is not uncommon to read files in excess of 700 megabytes.
Since these files can take over a minute to load, it would be helpful to show the user that progress is being made.
Is there a way to get the progress of textscan - ideally I'd send it to waitbar() or something similar, but any indication I can give my user will be a major improvement.
I have zero ideas at this point without implementing my own textscan, and that's not something I'm excited to undertake.
8 Comments
No can do...when you pass control to textscan it's got it until it returns.
You could write your code that if you were to look at the file size first, you could then partition the textscan call into blocks and after each is finished update an indicator then repeat until done.
textscan is a builtin function so you can't use the expedient of adding anything to the m-file so think the above is about it as it has no callback functionality.
ADDENDUM
Do you need the full flexibility of textscan to parse the files? If the structure is regular perhaps fscanf or one of the other "less developed" input routines would suffice and speed up the process significantly owing to less overhead of the complexity within textscan.
Nick Counts
on 24 Oct 2014
dpb
on 24 Oct 2014
help textscan
...
C = textscan(FID,'FORMAT',N) reads data from the file, using the FORMAT
N times, where N is a positive integer. To read additional data from
the file after N cycles, call textscan again using the original FID.
...
What's the format string you're using?
Nick Counts
on 25 Oct 2014
dpb
on 25 Oct 2014
"I can probably add %*[^\n] to the second one to ensure a line by line read through… Think that's necessary?"
Will be if you want to read subsections of the file in order to come back to the calling routine intermittently and update a progress indicator.
Are the data you're after actually strings or are you then also doing str2double or the like?
Are the files fixed-width columns or just comma-delimited variable length fields?
Nick Counts
on 25 Oct 2014
dpb
on 25 Oct 2014
Possibly move the sscanf step to scanf on the file would be one suggestion.
I'm thinking probably to get any further real input would need to see a section of the file under discussion and what it is you want from it.
Doesn't have to be large, just enough to illustrate the format and whatever "issues" it has altho sounds like it is at least regular.
Nick Counts
on 25 Oct 2014
Answers (0)
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!