I get "Index exceeds matrix dimensions" in Signal Processing
4 ビュー (過去 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!