フィルターのクリア

find matching values from two unequal size arrays

62 ビュー (過去 30 日間)
akk
akk 2018 年 11 月 10 日
コメント済み: akk 2018 年 11 月 11 日
I have two arrays of unequal length. [lat1 lon1 pCO2] say 200000 values in each column [lat2 lon2] say 100000 values in each column
I want to find where both lat2=lat1 and lon2=lon1, then take the pCO2 value from the first array and plug it into the second array as a new column.

採用された回答

Stephen23
Stephen23 2018 年 11 月 10 日
編集済み: Stephen23 2018 年 11 月 10 日
>> A1 = [1,2,3;4,5,6;7,8,9]
A1 =
1 2 3
4 5 6
7 8 9
>> A2 = [1,2;0,0;0,0;4,5]
A2 =
1 2
0 0
0 0
4 5
>> [ida,idb] = ismember(A2,A1(:,1:2),'rows');
>> A2(:,3) = NaN;
>> A2(ida,3) = A1(idb(ida),3)
A2 =
1 2 3
0 0 NaN
0 0 NaN
4 5 6

その他の回答 (2 件)

madhan ravi
madhan ravi 2018 年 11 月 10 日
[ia,c,ib]=ismember(lat1,lat2)
  2 件のコメント
akk
akk 2018 年 11 月 10 日
Thanks, but lon1 must also equal lon2
madhan ravi
madhan ravi 2018 年 11 月 10 日
[ia1,c1,ib1]=ismember(lon1,lon2)

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


Andrei Bobrov
Andrei Bobrov 2018 年 11 月 10 日
Let:
a = [lat1 lon1 pCO2];
b = [lat2 lon2];
b(:,3) = a(ismember(a(:,1:2),b,'rows'),3);
  1 件のコメント
akk
akk 2018 年 11 月 10 日
Thanks! This works! Only, because there are some rows in b without a match in a, b (:,3) is smaller than the number of rows in b. Is there a way to fill in those missing rows with a nan instead?

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

カテゴリ

Help Center および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by