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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by