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');

回答 (1 件)

Star Strider
Star Strider 2015 年 5 月 9 日

0 投票

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 件のコメント

Nicole Scerri
Nicole Scerri 2015 年 5 月 9 日
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?
Walter Roberson
Walter Roberson 2015 年 5 月 9 日
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 2015 年 5 月 9 日
@Walter — Thank you. Away for a bit here. Life intrudes.

この質問は閉じられています。

タグ

質問済み:

2015 年 5 月 9 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by