Info

This question is closed. Reopen it to edit or answer.

How do i use textscan for quality control?

1 view (last 30 days)
Nicole Scerri
Nicole Scerri on 9 May 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a file with this data. YY/MM/DD HH -Level- Atm.Prs -Tw- 09/06/15 00 0.0492 1019.24 25.5
I'm trying to do some quality control to the data, so i'd like to read it, add an extra column to add flags, check for spikes, fix NaNs and a few more procedures.
I tried to use fopen and then textscan, but it says that Param/value pairs must come in pairs. What am I doing wrong? this is the code:
fid = fopen('090615.m43', 'r');
T = textscan(fid, 'ReadVariableNames', false, 'format', '%s%d%f%f%f', 'HeaderLines',1 , 'Delimiter', 'tab');

Answers (1)

Star Strider
Star Strider on 9 May 2015
It’s probably choking on 'tab' and some other small problems. Use '\t' instead:
T = textscan(fid, '%s%d%f%f%f', 'HeaderLines',1 , 'Delimiter', '\t');
I removed 'ReadVariableNames', false, because that is not in my R2015a documentation for textscan. If it’s in your version, keep them in.
With these changes, it should work (although I don’t have your file to check it).
  3 Comments
Walter Roberson
Walter Roberson on 9 May 2015
rowhasnan = isnan(T{2}) | isnan(T{2}) | isnan(T{4}) | isnan(T{5});
T.flag(rowhasnan) = 6;
If you want to display the final table, you could use fprintf() in a loop, or if you have a new enough MATLAB version you could use the table facility
Star Strider
Star Strider on 9 May 2015
@Walter — Thank you. Away for a bit here. Life intrudes.

Tags

Community Treasure Hunt

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

Start Hunting!