Finding a range of data greater than 0.1
3 views (last 30 days)
Show older comments
Sahar khalili
on 17 Jun 2021
Commented: Sahar khalili
on 18 Jun 2021
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]
0 Comments
Accepted Answer
Alan Stevens
on 18 Jun 2021
Edited: Alan Stevens
on 18 Jun 2021
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)
3 Comments
Alan Stevens
on 18 Jun 2021
The following will pick out the starting column numbers
find(X==XX(1,1))
find(X==XX(2,1))
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!