index exceeds matrix dimension
1 回表示 (過去 30 日間)
古いコメントを表示
I am calculating mean squared errors for 5 different methods using 3 different sigmas. Each Method is going to be a composition of a 5 X 3 matrix. For hours I have been trying to figure this out but I cannot possibly figure out what I am doing wrong. I keep getting this error:
Index exceeds matrix dimensions.
Error in AR_1_2 (line 61)
MSE_CV(iLoop,:) = (1/length(ycnoise))*sum((yHatCV(iLoop,:) - origFun).^2);
HERE IS THE CODE BELOW
*****************************************************************************
for iLoop = 1:5
MSE_CV = zeros(5,length(sigma));
MSE_plugIN = zeros(5,length(sigma));
MSE_Mean_Max_SNR = zeros(5,length(sigma));
MSE_maxSNR = zeros(5,length(sigma));
MSE_Poly_SNR = zeros(5,length(sigma));
%for j = 1: length(sigma)
MSE_CV(iLoop,:) = (1/length(ycnoise))*sum((yHatCV(iLoop,:) - origFun).^2);
MSE_plugIN(iLoop,:) = (1/length(ycnoise))*sum((yHatPlugIn(iLoop,:) - origFun).^2);
MSE_Mean_Max_SNR(iLoop,:) = (1/length(ycnoise))*sum((yHatSNRmeanBW(iLoop,:) - origFun).^2);
MSE_maxSNR(iLoop,:) = (1/length(ycnoise))*sum((yHatSNRAll(iLoop,:) - origFun).^2);
MSE_Poly_SNR(iLoop,:) = (1/length(ycnoise))*sum((yHatSNRfinalBW(iLoop,:) - origFun).^2);
end
2 件のコメント
Walter Roberson
2017 年 7 月 18 日
What is size(yHatCV) ? And is it possible that you have a variable named "sum" ?
Image Analyst
2017 年 7 月 18 日
Since you're creating new versions of those arrays at the beginning of each iteration, only the iLoop row will get set. After the loop is done only row 5 of all the matrices will have anything in them. Maybe you want the zeros() preallocation before the loop even starts.
採用された回答
Jan
2017 年 7 月 18 日
編集済み: Jan
2017 年 7 月 18 日
Use the debugger to identify the problem. Type this in the command window
dbstop if error
or use the corresponding menu in the editor. Then run te code again until it stops at the error. Now check the locally used variables and functions either in the CommandWindow or in the WorkSpace browser:
% MSE_CV(iLoop,:) = (1/length(ycnoise))*sum((yHatCV(iLoop,:) - origFun).^2);
iLoop
size(MSE_CV)
which('length') % Function shadowed by local variable?
length(ycnoise)
which('sum') % Function shadowed by local variable?
yHatCV(iLoop,:)
sum((yHatCV(iLoop,:) - origFun).^2)
The debugger is the best friend of the programmer. Learn how to use it efficiently.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
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!