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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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

Weitere Antworten (1)

KSSV
KSSV am 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')

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by