Help with isnan with two matrices of unequal dimensions

1 回表示 (過去 30 日間)
Sayantan Sahu
Sayantan Sahu 2018 年 1 月 15 日
回答済み: Guillaume 2018 年 1 月 16 日
Hi,
I have two matrices of unequal dimensions. pol1 = 1 x 22648 and pol2 has dimensions of 1 X 22706.
I wanted to plot one against the other and I want to check the cells for which both values exist.
I tried good_use=find(~isnan(pol1) & ~isnan(pol2))
but I get an error ' Matrix dimensions must agree '.
How do I solve this error ?
  4 件のコメント
Guillaume
Guillaume 2018 年 1 月 15 日
"I want to find the indices for which both pol1 and pol2 have values"
You still haven't explained what that means when the two vectors have different length. Using shorter vectors, if
pol1 = [1 nan 2 nan]
pol2 = [nan 3 4 nan nan 5]
what result would you expect ?
Sayantan Sahu
Sayantan Sahu 2018 年 1 月 16 日
yes use shorter vectors. In the example you provide, it should plot pol1(3) and pol2(3) and so on. To summarize wherever its numeric values not NaN.

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

採用された回答

Guillaume
Guillaume 2018 年 1 月 16 日
"yes use shorter vectors"
So in effect, you're telling us to truncate the longer one so that it is the same length as the other? If you do that then your initial expression will work.
%truncate longer vector to the size of the shorter vector:
veclength = min(numel(po1), numel(pol2));
pol1 = pol1(1:veclength);
pol2 = pol2(1:veclength);
%your original search, find not needed
good_use = ~isnan(pol1) & ~isnan(pol2)
%plot
plot(pol1(good_use), pol2(good_use))

その他の回答 (1 件)

Greg Heath
Greg Heath 2018 年 1 月 15 日
Separate the 2 searches.
Hope this helps
Thank you for formally accepting my answer
Greg

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by