How do i use textscan for quality control?

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)

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

Yep! It's working :)
I want to add a flag column, then look for NaNs. If there is a NaN I'd like it to change the NaN to a 999 and change the corresponding number in the flag column to 6.
I got this far:
T.flag = zeroes(size(T,1),1);
Also, is there a way to show the final table?
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
@Walter — Thank you. Away for a bit here. Life intrudes.

This question is closed.

Tags

Asked:

on 9 May 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!