Effacer les filtres
Effacer les filtres

index exceeds matrix dimension

1 vue (au cours des 30 derniers jours)
Osita Onyejekwe
Osita Onyejekwe le 17 Juil 2017
Modifié(e) : Jan le 18 Juil 2017
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 commentaires
Walter Roberson
Walter Roberson le 18 Juil 2017
What is size(yHatCV) ? And is it possible that you have a variable named "sum" ?
Image Analyst
Image Analyst le 18 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 18 Juil 2017
Modifié(e) : Jan le 18 Juil 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.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by