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

1 回表示 (過去 30 日間)
Rayan Glus
Rayan Glus 2021 年 11 月 27 日
コメント済み: Rayan Glus 2021 年 11 月 27 日
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
Walter Roberson 2021 年 11 月 27 日
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

その他の回答 (1 件)

KSSV
KSSV 2021 年 11 月 27 日
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 件のコメント
Rayan Glus
Rayan Glus 2021 年 11 月 27 日
Thank you for your answer. Idx starts from 13 though instead of 14.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by