Effacer les filtres
Effacer les filtres

How can I find the index of a specific element in an array

3 vues (au cours des 30 derniers jours)
Rayan Glus
Rayan Glus le 27 Nov 2021
Commenté : Rayan Glus le 27 Nov 2021
I have a vector T of size 1 by 30. The values of its elements start from zero and go to a maximum value and then decay back to zero.
How can I find the index of the element that satisfies <= .05 * R only in the decaying region of T?
R = 5000;
T = [0 8 39.3 103 236.5 511.7 1026.1 1906.9 3148.7 4293 4011.9 2628.4 1037.4 203.7 28.6 9.4 4.2 1.4 1.3 0.6 0.1 0 0 0 0 0 0 0 0 0]
Thanks

Réponse acceptée

Walter Roberson
Walter Roberson le 27 Nov 2021
R = 5000;
T = [0 8 39.3 103 236.5 511.7 1026.1 1906.9 3148.7 4293 4011.9 2628.4 1037.4 203.7 28.6 9.4 4.2 1.4 1.3 0.6 0.1 0 0 0 0 0 0 0 0 0];
[~, maxidx] = max(T);
idx = find( (T <= 0.05 * R) & (maxidx <= 1:length(T)) )
idx = 1×17
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Plus de réponses (1)

KSSV
KSSV le 27 Nov 2021
R = 5000;
T = [0 8 39.3 103 236.5 511.7 1026.1 1906.9 3148.7 4293 4011.9 2628.4 1037.4 203.7 28.6 9.4 4.2 1.4 1.3 0.6 0.1 0 0 0 0 0 0 0 0 0] ;
x = 1:length(T);
%Get max value from T
[val,id] = max(T) ;
% Condition
idx = find(T<=0.5*R) ;
% Pick only those greater then id
idx(idx<id)=[];
plot(x,T)
hold on
plot(x(idx),T(idx),'*r')
  1 commentaire
Rayan Glus
Rayan Glus le 27 Nov 2021
Thank you for your answer. Idx starts from 13 though instead of 14.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by