Undefined function or variable error

1 view (last 30 days)
Hi Guys,
I am a noob in Matlab. I have to calculate different parameters (Bias, BSS, RMSE) alongst a Dune (402 slots) for 250 different profiles. I keep gettint the error Undefined function or variable 'simu'. on the last couple of lines of the Code. I dont know what i am doing wrong...please help?
clear; close all
currentFolder = pwd;
ncFil = fullfile(pwd,'xboutput.nc');
x= nc_varget(ncFil,'globalx');
y= nc_varget(ncFil,'globaly');
zb= nc_varget(ncFil,'zb');
zb_post = load('C:\Users\matth\Desktop\XBeach_MPI\v00_default\POSTmeas\XB_HuMo_POST_nx403ny251_ang326.dep');
zb_ref= load('C:\Users\matth\Desktop\XBeach_MPI\v00_default\Sim\XB_HuMo_FELDENS_OptDep_Dx11-4_Dy4_nx403ny251_ang326_wd-25.dep');
%ny=250
%nx=402
BSS = zeros(250,1) * NaN;
BIAS = zeros(250,1) * NaN;
RMSE = zeros(250,1) * NaN;
for i = 1:250
BSS_i = 0;
Bias_i = 0;
RMSE_i = 0;
for j = 1:402
if nanmean(zb_post(i,j)) == 1
simu = squeeze(zb(end,i,:));
mess = squeeze(zb_post(i,:)).';
ref = squeeze(zb_ref(i,:)).';
end
end
%Variablen belegen
BSS(j,1) = 1 - (sum((simu-mess).^2)/length(simu))/(sum((ref-mess).^2)/length(ref));
Bias(j,1) = sum((simu(:)-mess(:)))/numel(simu);
RMSE(j,1) = sqrt(sum((simu(:)-mess(:)).^2)/numel(simu));
end

Accepted Answer

Adam Danz
Adam Danz on 1 Oct 2019
Edited: Adam Danz on 2 Oct 2019
'simu' and other variables are only defined when nanmean(zb_post(i,j)) == 1. If that nanmean() is not equal to exactly 1, 'simu' and other variables are never defined. To fix that, define simu, mess, & reff when the nanmean is not equal to 1.
if nanmean(zb_post(i,j)) == 1
simu = squeeze(zb(end,i,:));
mess = squeeze(zb_post(i,:)).';
ref = squeeze(zb_ref(i,:)).';
else
simu = ???
mess = ???
ref = ???
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!