Separating a matrix into two matrices based on a value of one of the columns.
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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,:)};
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!