## Extracting a matrix by row and column from a large matrix

Tanmoyee Bhattacharya

### Tanmoyee Bhattacharya (view profile)

さんによって質問されました 2019 年 5 月 21 日

さんによって コメントされました 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.

Bob Nbob

### Bob Nbob (view profile)

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]?

2019 年 5 月 21 日
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

サインイン to comment.

## 1 件の回答

2019 年 5 月 21 日

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 件のコメント

サインイン to comment.

Translated by