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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!