How can I solve this error?
2 views (last 30 days)
I'm not able to plot this because I get an error without explanation.
Can anyone help me, please?
% read in data
lakeData = readtable('test_C.csv');
% pull out mbt5me for ease
mbt5me = lakeData.MBT5Me;
% set prior mean, standard deviation, and model type
prior_mean = 10;
prior_std = 10;
model = "T0";
% calibrate both uncorrected mbt and corrected mbt:
calibratedData = baymbt_predict(mbt5me,prior_mean,prior_std,model,"lake");
% plot the median values and 1-sigma confidence intervals
p1=plot(lakeData.Year,calibratedData.T(:,2)); hold on;
legend([p1 p2 p3],'Median','Lower 1-sigma','Upper 1-sigma');
ylabel('MAT above zero');
Jan on 11 Mar 2022
Edited: Jan on 11 Mar 2022
Omit the lines:
Note, that clear all deletes all loaded functions from the RAM and reloading them from the slow disk wastes time only. This does not have any benefits.
Then read the error message: Scripts must be defined on top of the M-files. Functions used inside the script must be defined on bottom. Your file baymbt_predict.m is a script (because it does not start with the keyword "function"). It runs the two brute clearing commands. Then an empty function is created:
function output = baymbt_predict(mbt5me,prior_mean,prior_std,Tmodel,Type)
And in line 53 another script is started. Now the error message tells you, that this is not allowed, because you have a function defined before.
I guess, you want to remove the two "clear and close" lines, and move the "end" from line 7 to the bottom of the code. Then the file baymbt_predict.m becomes a function and calling it with inputs gets meaningful:
Read the documentation to learn the differences between scripts and functions.