I get "Index exceeds matrix dimensions" in Signal Processing

6 vues (au cours des 30 derniers jours)
Luis Pedro Cobos
Luis Pedro Cobos le 5 Déc 2015
Modifié(e) : Stephen23 le 7 Déc 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
  2 commentaires
Walter Roberson
Walter Roberson le 5 Déc 2015
What are you passing in as fm? Your .mat file does not contain it.
Luis Pedro Cobos
Luis Pedro Cobos le 7 Déc 2015
fm is 2048

Connectez-vous pour commenter.

Réponses (2)

Sam Muldoon
Sam Muldoon le 7 Déc 2015
Modifié(e) : Sam Muldoon le 7 Déc 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 commentaires
Luis Pedro Cobos
Luis Pedro Cobos le 7 Déc 2015
I have no 247 anywhere on my code
Stephen23
Stephen23 le 7 Déc 2015
Modifié(e) : Stephen23 le 7 Déc 2015
@Sam Muldoon: +1 for a clear explanation and example.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 7 Déc 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');

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by