フィルターのクリア

Replace values in one column based on the content in several other columns.

2 ビュー (過去 30 日間)
merialu
merialu 2018 年 11 月 13 日
コメント済み: merialu 2018 年 11 月 14 日
Hi
I have two matrices containing x,y and z coordinates. These matrices also contain a column with values for each point.
Looks something like this:
A=[x y z value, 1 1 1 1; 1 2 1 0, 2 1 1 3, 2 1 2 4]
B=[x y z value, 1 1 1 1; 1 2 1 0]
the first matrix (A) have much more values than the second one (B). What i am trying to do is to replace the values in the large matrix (A) with the values from the smaller matrix (B) whenever the coordinates are the same. Thus the values in the x y and z column need to match.
Any ideas how to solve this?

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 13 日
A = [1 1 1 0;
1 2 1 1;
2 1 1 3;
1 1 1 3;
2 1 2 4]
B = [1 1 1 1;
1 2 1 0]
[b,loc] = ismember(A(:,1:3),B(:,1:3),'rows');
A(b,:) = B(loc(b),:);
The result after replacement is
A =
1 1 1 1
1 2 1 0
2 1 1 3
1 1 1 1
2 1 2 4
  1 件のコメント
merialu
merialu 2018 年 11 月 14 日
Hi, Sorry for a delayed answer. This works great. Thank you!

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 13 日
A=[ 1 1 1 1; 1 2 1 0; 2 1 1 3; 2 1 2 4] %perhaps?
B=[ 1 1 1 1; 1 2 1 0]
index=ismember(A(1:3,:),B,'rows')
A(index,:)=somevalues

Community Treasure Hunt

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

Start Hunting!

Translated by