Returning only positive values of a data set

73 visualizaciones (últimos 30 días)
jacob Mitch
jacob Mitch el 24 de Nov. de 2019
Respondida: Star Strider el 24 de Nov. de 2019
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%
%

Respuestas (1)

Star Strider
Star Strider el 24 de Nov. de 2019
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

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by