nansum alternative coding for operations and plotting figures.

Hello,
I am reciving a message from MATLAB saying that 'nansum' use is not reccomended and to use 'sum' instead, with the appropriate code changes.
However, I have data that needs to be operated on (sum/difference/division/etc.) and at the same time this data needs to be plotted in figures.
Using '0's' in place of NAN is fine for operating on, but when I use '0' for plotting, MATLAB thinks '0' is a value and fills in with color. The only way I've ever found it possible to plot '0' values as empty is by using 'NAN's'.
I am specifically using the 'patch' function to plot my data.
Just wondering if there is someone out there that can offer coding changes to agree more with MATLAB reccomendations.
Thanks.

2 件のコメント

Mike Hosea
Mike Hosea 2021 年 8 月 19 日
Are you saying that if you could use nansum, you wouldn't have a problem? With SUM you do not need to convert NaNs to zeros. You just add the 'omitnan' flag to your sum call.
>> x = magic(3)
x =
8 1 6
3 5 7
4 9 2
>> x(2,2) = nan
x =
8 1 6
3 NaN 7
4 9 2
>> sum(x,1,'omitnan')
ans =
15 10 15
>> sum(x,2,'omitnan')
ans =
15
10
15
Eric Escoto
Eric Escoto 2021 年 8 月 19 日
Hi Mike,
I used the 'omitnan' flag in my scripts and it works out.
Thanks!

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 8 月 19 日

コメント済み:

2021 年 8 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by