How to remove certain elements in a matrix according to the value of elements in an array

조회 수: 1 (최근 30일)
Hi all,
I want to manipulate a matrix according to the values in the first column. I want to remove rows which their values on the first column is less than 5. Here is an example
Original:
5 6
2 1
4 2
7 9
9 5
New matrix:
5 6
7 9
9 5

채택된 답변

Voss
Voss 2022년 6월 20일
A = [
5 6
2 1
4 2
7 9
9 5
]
A = 5×2
5 6 2 1 4 2 7 9 9 5
idx = A(:,1) < 5;
A(idx,:) = []
A = 3×2
5 6 7 9 9 5

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by