Separating a matrix into two matrices based on a value of one of the columns.

So I have a matrix like such
Data2 =
and I want to separate the matrix into two different matrices based on the 4th column. I want to have two separate matrices where one has only rows with a number above zero in column 4 and the other has only values with zero in column 4. I am also set with the stipulations that I cannot use If statements. any ideas?
Thank you for your time.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 2월 28일
편집: Andrei Bobrov 2013년 2월 28일
p = data(:,4) > 0; % here 'data' - your array
out = {data(p,:), data(~p,:)};
if there is a negative value, then
out = {data(data(:,4) > 0,:), data(data(:,4) == 0,:)};

댓글 수: 2

Thomas
Thomas 2013년 2월 28일
편집: Thomas 2013년 2월 28일
I after I use this it creates another vector named out that references two separate areas of my first peace of data. After i click on the matrix and it brings up a table it shows two different things. One is 46x6 double in the area 1,1 on my table while the other is 4x6 double in the area 2,1. Is there a way to make it so I can set those values to show up like a normal matrix would after clicking on it?
Never mind I figured it out

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2013년 2월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by