Cumtrapz for matrix including NaN values

31 ビュー (過去 30 日間)
Anna S
Anna S 2019 年 4 月 15 日
コメント済み: Anna S 2019 年 4 月 15 日
I want to integrate a data field which sometimes also contains Nan values. The integration with cumtrapz then always is NaN as well, of course.
Is there a function (as for example nanmean instead of mean) which ignores NaN?
SALT = [ NaN NaN NaN NaN
NaN NaN NaN NaN
31.7313 NaN NaN NaN
31.9400 31.6944 NaN NaN
32.1753 31.9462 NaN NaN
32.2596 32.0371 31.7931 NaN
32.3248 32.2337 32.0498 NaN]
Q= cumtrapz(SALT)

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 4 月 15 日
Well, I think that in addition to calculating a cummulative integration you also should/need to extract the limits over which you have non-nan values, something like this:
for i2 = 1:size(SALT,2)
i1 = find(isfinite(SALT(:,i2)));
if ~isempty(i1)
I_OK(:,i2) = [i1(1) i1(end)];
CTS{i2} = cumtrapz(SALT(i1,i2));
end
end
In addition you should only use cumtrapz over contiguous regions with finite values, so my example works for the data you gave. You might(should) make sure that the indices i1 are without gaps/or take care of the cases where there are gaps.
HTH
  1 件のコメント
Anna S
Anna S 2019 年 4 月 15 日
Thanks, that's what I was searching for!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by