필터 지우기
필터 지우기

Returning only positive values of a data set

조회 수: 51 (최근 30일)
jacob Mitch
jacob Mitch 2019년 11월 24일
답변: Star Strider 2019년 11월 24일
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에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by