Undefined function or variable error

조회 수: 2 (최근 30일)
Matthias Wernerus
Matthias Wernerus 2019년 10월 1일
편집: Adam Danz 2019년 10월 2일
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

채택된 답변

Adam Danz
Adam Danz 2019년 10월 1일
편집: Adam Danz 2019년 10월 2일
'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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by