Using isinf and isnan in the same command line?

6 ビュー (過去 30 日間)
Jesse
Jesse 2015 年 7 月 27 日
コメント済み: Jesse 2015 年 7 月 27 日
Greetings all,
Trying to compute some statistics for a particular data array that has Nan and Inf values scattered throughout.
Right now as an example, for one of the arrays, I have the following line: std_sigma1outs=cellfun(@(a)std(a(~isinf(a))),sigma1outs);
So, two questions. 1.) Can I use isinf and isnan on the same array in the same line? 2.) Reading the help files, I see that I can exclude NaNs in std (omitNaN flag). What about excluding Inf's simultaneously? Can someone give me example with my command line I provided to see how that combination would be coded?
Thanks! -J

採用された回答

Brendan Hamm
Brendan Hamm 2015 年 7 月 27 日
f = @(a) std(a(~isinf(a) & ~isnan(a)));
% f = @(x) std(a(~isinf(a)),'omitnan');
std_sigma1outs=cellfun(f,sigma1outs);
Either way will work fine, but omitnan is a more recent addition to the statistical functions in base MATLAB, so I provide both. The first version utilizes the 'and' operator:
>> true & true
ans =
1
>> false & false
ans =
0
>> true & false
ans =
0
>> false & true
ans =
0
  1 件のコメント
Jesse
Jesse 2015 年 7 月 27 日
Great thanks Brendan!
-Jesse

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

その他の回答 (1 件)

Jan
Jan 2015 年 7 月 27 日
~isnan(X) & ~isinf(X) is the same as isfinite(X).
  1 件のコメント
Jesse
Jesse 2015 年 7 月 27 日
Oh! I didn't know that but thanks for the feedback Jan.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by