extract a slice from a 2D matrix with specific values

조회 수: 26 (최근 30일)
Lama Hamadeh
Lama Hamadeh 2021년 12월 16일
댓글: Lama Hamadeh 2021년 12월 16일
Hi,
I want to extract a slice of a 2D matrix from a bigger 2D matrix with certain values. So, if I have a matrix as follwoing:
M = [1 2;
1 4;
7 1
9 1
0 3
0 4
9 0
8 0];
And I want to extract a slice that only has values in the second column equal one.
Any help would be appreicted.
Thanks.

채택된 답변

Chunru
Chunru 2021년 12월 16일
M = [1 2;
1 4;
7 1
9 1
0 3
0 4
9 0
8 0];
y = M(M(:,2)==1, :)
y = 2×2
7 1 9 1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by