필터 지우기
필터 지우기

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

조회 수: 3 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by