How to split a matrix by a column by whether values are greater or less than a number
이전 댓글 표시
I have a matrix:

I would like to split this into two new matrices which are dependent on whether the values in column C are greater than 7 or less than 7.
I have tried a loop:
for i=1:12
if matrix(i,3)>7
A=(matrix(i,:))
elseif matrix(i,3)<7
B=(matrix(i,:))
end
end
this did not give me two matrices.
Can anyone help? Many thanks
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2016년 1월 20일
A=randi(10,6,3)
idx=A(:,3)>7
A1=A(idx,:)
A2=A(~idx,:)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!