フィルターのクリア

Determine if a value is an Empty Matrix: 0 x 1 and replace with NaN

10 ビュー (過去 30 日間)
Theodore
Theodore 2013 年 7 月 23 日
Hello. In my code I'm attempting to locate the max value of a variable. Unfortunately for doing max(variable) it gives an error if the matrix is a []. I was trying to figure out how to properly write my if else loop to put in NaN to a previously defined array if its a [] and if not, to calculate the value. My code is as follows:
if l == 1
fint=intersect(find(b(:,1)==k),find(b(:,2)==l))
if fint == []
high_maxT_mo(k - (minyear-1),1) = NaN
else
high_maxT_mo(k - (minyear-1),1) = nanmax(maxtemp(fint))
end
end
I get the following:
fint =
Empty matrix: 0-by-1
Error using == Matrix dimensions must agree.
Thanks!
  1 件のコメント
Theodore
Theodore 2013 年 7 月 23 日
k is a variable defined in my for loop spanning from k=minyear:maxyear.

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

採用された回答

Evan
Evan 2013 年 7 月 23 日
編集済み: Evan 2013 年 7 月 23 日
help isempty
Your code would look something like this:
if l == 1
fint = intersect(find(b(:,1)==k),find(b(:,2)==l))
if isemty(fint)
high_maxT_mo(k - (minyear-1),1) = NaN
else
high_maxT_mo(k - (minyear-1),1) = nanmax(maxtemp(fint))
end
end
  1 件のコメント
Theodore
Theodore 2013 年 7 月 23 日
Awesome! Thanks so much! Worked perfectly!

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

その他の回答 (2 件)

Jan
Jan 2013 年 7 月 23 日
A simplification for:
fint=intersect(find(b(:,1)==k),find(b(:,2)==l))
is:
fint = find(b(:,1)==k & b(:,2)==l)

the cyclist
the cyclist 2013 年 7 月 23 日
Rather than doing an equality comparison
if fint == [],
use the isempty function:
if isempty(fint)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by