Extracting a matrix by row and column from a large matrix

조회 수: 1 (최근 30일)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2019년 5월 21일
댓글: Adam Danz 2019년 5월 21일
I have a matrix like
1 1 1 2000
1 1 1 2000
1 1 1 2000
2 2 2 3000
2 2 2 3000
2 2 2 3000
3 3 3 5000
3 3 3 5000
3 3 3 5000
I have another matrix
2 2 2
2 2 2
2 2 2
I want a matrix from this matrix large matrix given above
2 2 2 3000
2 2 2 3000
2 2 2 3000
Can anyone help to extract the values through matlab.I am trying throuh ismember but not working.
  댓글 수: 2
Bob Thompson
Bob Thompson 2019년 5월 21일
What kind of conditions are you hoping to meet, or do you literally just want any row which contains [2 2 2 3000]?
Adam Danz
Adam Danz 2019년 5월 21일
Tanmoyee Bhattacharya answer moved here
I have another matrix
2 2 2
2 2 2
2 2 2
I have to extract the 4,5,6 row and four column from the large matrix by the given matrix
2 2 2 3000
2 2 2 3000
2 2 2 3000

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

채택된 답변

Adam Danz
Adam Danz 2019년 5월 21일
편집: Adam Danz 2019년 5월 21일
I changed your example matrix a bit to make sure it ignores partial pattern matches.
m = [1 1 1 2000
1 1 1 2000
1 1 1 2000
2 2 2 3000
2 2 2 3000
2 2 2 3000
3 3 3 5000
3 3 3 5000
3 3 3 5000
2 2 2 6000
2 2 2 6000
9 9 9 7000];
s = [2 2 2
2 2 2
2 2 2];
[~, rowIdx] = intersect(m,s);
mSubset = m(rowIdx+(0:size(s,1)-1),:);
Result
mSubset =
2 2 2 3000
2 2 2 3000
2 2 2 3000
Note that if there is more than 1 match it will only return the first subset match.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by