I'm getting an error (Index in position 1 exceeds array bounds)

조회 수: 1 (최근 30일)
Majd AG
Majd AG 2022년 10월 5일
댓글: Majd AG 2022년 10월 8일
I'm trying to find the onset point of a transient signal by comparing it with a threshold value calculated based on the base-level of this signal. However, when I try to find the index of such a point it returns and index out of bounds, I can't figure out why. Here's my code
signal = maximum_env_ch2; % 65536x2 array (time, voltage)
max_thresh = max(signal(1:floor(0.3*end),2)); %threshold calculated form the first part of the signal (zero-level)
ind_out = find( signal > max_thresh ,1); %find index of point>thresh
onset = signal(ind_out,1); %return onset time

채택된 답변

Jeffrey Clark
Jeffrey Clark 2022년 10월 5일
@Majd AG, find is going to look at the entire signal as if you had written signal(:) > max_thresh; find will return values beyond the first index limit. I expect you want:
ind_out = find( signal(:,2) > max_thresh ,1);
But also note that since max_thresh is from the signal it may be the actual max and therefore there is no signal(:,2)>max_thresh; find will return ind_out as an empty array which will also fail as an index.
  댓글 수: 1
Majd AG
Majd AG 2022년 10월 8일
Thanks for the answer. indeed the problem was not specifiying the amplitude column (:,2) in find function.
and for your second note, in my case max_thresh is definitely not the maximum since it represent the highest point in the zero-level before the actual signal begins.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Davide Masiello
Davide Masiello 2022년 10월 5일
Do this instead
ind_out = signal(1,:) > max_thresh; %find index of point>thresh
onset = signal(ind_out,1); %return onset time


Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by