I get "Index exceeds matrix dimensions" in Signal Processing
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Sam Muldoon
il 7 Dic 2015
Modificato: Sam Muldoon
il 7 Dic 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 Commenti
Walter Roberson
il 7 Dic 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');
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!