Finding a range of data greater than 0.1

조회 수: 3 (최근 30일)
Sahar khalili
Sahar khalili 2021년 6월 17일
댓글: Sahar khalili 2021년 6월 18일
I have a range of data, for example like this
X = [ 0.02 0.17 0.32 0.28 0.04 -0.07 -0.01 -0.19 -0.45 -0.49 0.01 0.05 0.11 0.18 0.48 1.14 1.43 1.78 2.3 1.6 1.0 -0.1 0.1 0-2]
I want to find a range of X that all values in that range are greater than 0.1. I use this: find((X >= .1) ,1,'first') and find(X >= .1) ,1,'last')
but all data in that range are not greather than 0.1. And at last I want to find the longest range that has values more than 0.1.
In this example the answer is [0.11 0.18 0.48 1.14 1.43 1.78 2.3 1.6 1.0]

채택된 답변

Alan Stevens
Alan Stevens 2021년 6월 18일
편집: Alan Stevens 2021년 6월 18일
There must be a neater way, but the following might help:
X = [ 0.02 0.17 0.32 0.28 0.04 -0.07 -0.01 -0.19 -0.45 ...
-0.49 0.01 0.05 0.11 0.18 0.48 1.14 1.43 1.78 2.3 ...
1.6 1.0 -0.1 0.1 0-2];
Xptr = 0; Yptr = 1; row = 1;
while Xptr<numel(X)
Xptr = Xptr+1;
if X(Xptr)>0.1
Y(row,Yptr)=X(Xptr);
Yptr = Yptr+1;
elseif Xptr>1
row = row+1;
Yptr = 1;
end
end
XXptr = 1;
[r, c] = size(Y);
for i = 1:r
if Y(i,1)>0
XX(XXptr,:) = Y(i,:);
XXptr = XXptr+1;
end
end
disp(XX)
0.1700 0.3200 0.2800 0 0 0 0 0 0 0.1100 0.1800 0.4800 1.1400 1.4300 1.7800 2.3000 1.6000 1.0000
  댓글 수: 3
Alan Stevens
Alan Stevens 2021년 6월 18일
The following will pick out the starting column numbers
find(X==XX(1,1))
find(X==XX(2,1))
Sahar khalili
Sahar khalili 2021년 6월 18일
I do appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by