Finding a range of data greater than 0.1

3 次查看(过去 30 天)
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))

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by