I get "Index exceeds matrix dimensions" in Signal Processing
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Sam Muldoon
2015-12-7
编辑:Sam Muldoon
2015-12-7
"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 个评论
Walter Roberson
2015-12-7
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');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!