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

3 views (last 30 days)
Rayan Glus on 27 Nov 2021
Commented: Rayan Glus on 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

Walter Roberson on 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
Rayan Glus on 27 Nov 2021
Thank you so much.

KSSV on 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')
Rayan Glus on 27 Nov 2021