index exceeds matrix dimension
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 18 Jul. 2017
What is size(yHatCV) ? And is it possible that you have a variable named "sum" ?
Image Analyst
am 18 Jul. 2017
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.
Akzeptierte Antwort
Jan
am 18 Jul. 2017
Bearbeitet: Jan
am 18 Jul. 2017
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!