Finding a range of data greater than 0.1
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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]
0 commentaires
Réponse acceptée
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)
3 commentaires
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))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Discrete Fourier and Cosine Transforms 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!