MATLAB Answers

How to replace char 'null' in number 0?

36 ビュー (過去 30 日間)
Bizzy Dy
Bizzy Dy 2018 年 8 月 9 日
コメント済み: Guillaume 2018 年 8 月 9 日
Hi! I`ve got a problem with using plot function cause there is some 'null's (char type) in my data files . So i would like to change/replace that nulls in 0 (num) . Could someone help to find useful function or to offer other solution.

  6 件のコメント

表示 3 件の古いコメント
Stephen Cobeldick
Stephen Cobeldick 2018 年 8 月 9 日
Guillaume is right: fix the problem when it occurs, rather than trying to write hack code to "fix" it later. Upload a sample data file by clicking the paperclip button.
Bizzy Dy
Bizzy Dy 2018 年 8 月 9 日
done
Guillaume
Guillaume 2018 年 8 月 9 日
Please do not close questions that have been answered.

Sign in to comment.

採用された回答

Guillaume
Guillaume 2018 年 8 月 9 日
編集済み: Guillaume 2018 年 8 月 9 日
It's much easier to read your file with readtable (which also does not require any toolbox). It is trivial with readtable to convert the 'null' to 0 and read everything else as number.
t = readtable('result_3259_m.tsv', 'FileType', 'text', 'TreatAsEmpty', 'null', 'EmptyValue', 0);
t.time = datetime(t.time, 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss''Z''');
For further processing you may even want to convert the table to a timetable
I would also recommend that you do not extract the table columns into variables with meaningless names. Just use the table variables directly:
plot(t.time, t.input_flowrate_bezm, 'DatetimeTickFormat', 'dd.MM, HH:mm');

  1 件のコメント

Bizzy Dy
Bizzy Dy 2018 年 8 月 9 日
Thank you so much!

Sign in to comment.

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 8 月 9 日
The image shows a struct which char arrays as fields. You can use strrep() to replace the elements of a char array. Although it will still not work with the plot() function because the elements are char arrays, not numeric values. You might need to use str2num() to convert char values t numeric before using plot().

  0 件のコメント

Sign in to comment.

タグ

製品


リリース

R2017a

Translated by