필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

index exceeds matrix dimension

조회 수: 2 (최근 30일)
NIKITA
NIKITA 2012년 11월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
i am getting an error in the code to find peaks. Actually finding peaks is a function I am using for my main program to synchronize two files with respect to the time of the 2 files.
% pkind= index of the peak values % vlyind= index of valley % ind=index of sample when synch signal changes from hours to seconds
%% Peak Detection a=0; max = []; min = []; delta=0.15; % change this threshold if the peaks are not detected correctly d1=smooth(a); d2=1:length(d1); mn = 0; mx = 0; mnpos = 0; mxpos = 0;
lookformax = 1;
for i=1:length(d1) a1 = d1(i); if a1 > mx, mx = a1; mxpos = i; end if a1 < mn, mn = a1; mnpos = i; end
if lookformax
if a1 < mx-delta
max = [max ; mxpos mx];
mn = a1; mnpos = i;
lookformax = 0;
end
else
if a1 > mn+delta
min = [min ; mnpos mn];
mx = a1; mxpos = i;
lookformax = 1;
end
end
end
v1=max(:,2); v2=min(:,2); index=max(:,1); index2=min(:,1); t1=d2(index); t2=d2(index2); figure plot(d2,d1);hold on plot(t1,v1,'*r');hold on plot(t2,v2,'*r');hold off
The error is in v1,v2, index and index2. I am new to MATLAB and donot know the different functions which I could use or commands to handle the matrix dimension issue. I would be grateful if I could get some suggestions.

답변 (1개)

John Petersen
John Petersen 2012년 11월 1일
First of all, it's probably not a good idea to use reserved words for variable names, such as max and min. These are standard function calls in matlab. You can type
>>help max
for example, to see if it is reserved.
Where does the data go? You have what seems to be the data in "a" but it's initialized to 0 and never changes. So you'll never find a max or min and all your vectors will remain empty. When you try to index into an empty array, you will get an error message.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by