Returning only positive values of a data set
조회 수: 51 (최근 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%
%
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!