I get "Index exceeds matrix dimensions" in Signal Processing

4 Ansichten (letzte 30 Tage)
Luis Pedro Cobos
Luis Pedro Cobos am 5 Dez. 2015
Bearbeitet: Stephen23 am 7 Dez. 2015
When I try running my function with what was asked from me in my class thhis happens; can someone please help me:
Where S_1 to S_3 are attached
[vel1,corrcoef1] = p2( S_1,S_2,S_3,2048 )
Index exceeds matrix dimensions.
Error in p2 (line 9)
d1w=detrend(interp(d1(.5*i*fm+1:.5*fm(i+1)),20),'constant');
My code is this:
function [vel,corrcoef] = p2( Ss1,Ss2,Ss3,fm )
%Diferentials especifications
d1=Ss1-Ss2;
d2=Ss2-Ss3;
for i=0:313120
d1w=detrend(interp(d1(.5*i*fm+1:.5*fm(i+1)),20),'constant');
d2w=detrend(interp(d2(.5*i*fm+1:.5*fm(i+1)),20),'constant');
[corfun,lags]=xcorr(d1w,d2w);
fac=sqrt(sum(d1w.^2)*sum(d2w.^2));
normf=corfun/fac;
[corrcoef(i+1), pos]=max(normf);
delay=abs(lags(pos));
plot(lags,normf);
vel(i+1)=0.005/(delay/fm);
end
function is attached as well

Antworten (2)

Sam Muldoon
Sam Muldoon am 7 Dez. 2015
Bearbeitet: Sam Muldoon am 7 Dez. 2015
"Index exceeds matrix dimensions" means you tried to access an element of an array either before the array's begining, or more likely, after the array's end.
For example, if A = [1, 2, 3], then A(247) doesn't make very much sense, does it? There are only three elements in the array, how on earth could you access a 247th element of it?
247 is the "index." The dimensions of A are one row, and three columns. The index exceeds the matrix dimensions.
  2 Kommentare
Luis Pedro Cobos
Luis Pedro Cobos am 7 Dez. 2015
I have no 247 anywhere on my code
Stephen23
Stephen23 am 7 Dez. 2015
Bearbeitet: Stephen23 am 7 Dez. 2015
@Sam Muldoon: +1 for a clear explanation and example.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 7 Dez. 2015
Your code has
d1w=detrend(interp(d1(.5*i*fm+1:.5*fm(i+1)),20),'constant');
Notice the fm(i+1) . That is a request to index fm at position i+1 . Perhaps you omitted a multiplication,
d1w=detrend(interp(d1(.5*i*fm+1:.5*fm*(i+1)),20),'constant');

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by