필터 지우기
필터 지우기

How to extract rows from a parent matrix based on column values from a second matrix (child)?

조회 수: 2 (최근 30일)
I have 2 matrices: Parent matrix (19564 X 5) and a child matrix (3913 X 3) (sub-matrix of parent). The 3 cols in child matrix and 1st 3 cols in parent matrix are x,y and z - coordinates.
Parent= [x,y,z,A,B]
Child= [x,y,z]
I need to extract 4th and 5th column (A and B) from parent matrix corresponding to x,y,z coordinates in child matrix.
I tried using _ ismember_ function in MATLAB, but it performs a col-wise search and I don't get the desired output.
As output, I need a 3913 X 5 matrix whose 1st 3 cols are exactly same as the child matrix and then 2 additional cols (A and B) from parent matrix.

채택된 답변

Nitika Kandhari
Nitika Kandhari 2018년 3월 21일
out = Parent(ismember(Parent(:,1:3), Child, 'rows'), :);
is the solution I found from https://stackoverflow.com/questions/49401494/how-to-extract-rows-from-a-parent-matrix-based-on-column-values-from-a-second-ma Just in case someone else needs to perform a similar task.

추가 답변 (1개)

KSSV
KSSV 2018년 3월 21일
편집: KSSV 2018년 3월 21일
You can specify rows in ismember. It works along with rows also. Read the documentation properly.
  댓글 수: 2
Birdman
Birdman 2018년 3월 21일
rows option works for cases where both matrices have same number of rows.
KSSV
KSSV 2018년 3월 21일
Obviously yes........one has to pick first three columns from Parent.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by