Returning only positive values of a data set

42 次查看(过去 30 天)
If I a 3 row data set how would I return a new data set that only considers positive row 1 values for the first row
so If
Data=[1,-1,2,-1,3,4,5,-6;%x
1,2,3,4,-6,7,7,8;%y
6,2,3,4,5,6,7,8]%z
I want to get create a new data set with only x>0 values together with the corresponding y and z position values. So Im just getting rid of x<0 and corresponding y,z values So I would get
NewData=[1,2,3,4,5;%only positive x values
1,3,-6,7,7;6,3,5,6,7] %corresponding values in in that position%
%

回答(1 个)

Star Strider
Star Strider 2019-11-24
You cannot do exactly as you want, because the resulting matrix dimensions would not be compatible.
Likely the best you can do is:
Data=[1,-1,2,-1,3,4,5,-6;%x
1,2,3,4,-6,7,7,8;%y
6,2,3,4,5,6,7,8]%z
Pos = NaN(size(Data));
Lm = Data > 0;
Pos(Lm) = Data(Lm)
producing:
Data =
1 -1 2 -1 3 4 5 -6
1 2 3 4 -6 7 7 8
6 2 3 4 5 6 7 8
Pos =
1 NaN 2 NaN 3 4 5 NaN
1 2 3 4 NaN 7 7 8
6 2 3 4 5 6 7 8

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by