extract a slice from a 2D matrix with specific values

17 次查看(过去 30 天)
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