Effacer les filtres
Effacer les filtres

Finding a range of data greater than 0.1

7 vues (au cours des 30 derniers jours)
Sahar khalili
Sahar khalili le 17 Juin 2021
Commenté : Sahar khalili le 18 Juin 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]

Réponse acceptée

Alan Stevens
Alan Stevens le 18 Juin 2021
Modifié(e) : Alan Stevens le 18 Juin 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)
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 commentaires
Alan Stevens
Alan Stevens le 18 Juin 2021
The following will pick out the starting column numbers
find(X==XX(1,1))
find(X==XX(2,1))
Sahar khalili
Sahar khalili le 18 Juin 2021
I do appreciate it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by