Why am I not able to plot this?

1 view (last 30 days)
Pul
Pul on 9 Mar 2022
Commented: Pul on 9 Mar 2022
Hello everyone,
can anyone help me plot this, please?
I get an error at the first line.
Thank you very much
function output = baymbt_predict(mbt5me,prior_mean,prior_std,Tmodel,Type)
% Ensure column vector.
mbt5me=mbt5me(:);
% load appropriate model
if strcmp(Type,"lake")
load('baymbt0_params_lake.mat','b_draws_final','tau2_draws_final');
elseif strcmp(Type,"soil")
if strcmp(Tmodel,"T")
load('baymbt_params_soil.mat','b_draws_final','tau2_draws_final');
elseif strcmp(Tmodel,"T0")
load('baymbt0_params_soil.mat','b_draws_final','tau2_draws_final');
else
error('TModel not recognized - choices are "T" and "T0"');
end
else
error('Type not recognized - choices are "soil" and "lake"');
end
% get dimensions of time series and draws
nd = length(mbt5me);
n_draws = length(tau2_draws_final);
% parse parameters
alpha = b_draws_final(:,2);
betaT = b_draws_final(:,1);
sigma = sqrt(tau2_draws_final);
% Prior mean and inverse covariance matrix
pmu = repmat(ones(nd, 1) * prior_mean,1,n_draws);
pinv_cov = repmat(prior_std,nd,n_draws).^-2;
% Posterior calculations
post_mean_num = pinv_cov .* pmu + repmat(sigma',nd,1).^-2 .* repmat(betaT',nd,1) .* (mbt5me - repmat(alpha',nd,1));
post_mean_den = pinv_cov + repmat(betaT',nd,1).^2 .* repmat(sigma',nd,1).^-2;
post_mean = post_mean_num ./ post_mean_den;
post_sig = sqrt(post_mean_den.^-1);
output.ens = post_mean + randn(nd,n_draws).*post_sig;
output.prior_mean = prior_mean;
output.prior_std = prior_std;
if strcmp(Tmodel,"T0")
% if using BayMBT0, truncate at T < 0
output.ens(output.ens < 0) = NaN;
else
end
output.T = prctile(sort(output.ens,2),[2.5 50 97.5],2);
  2 Comments
Pul
Pul on 9 Mar 2022
I don't know why, but I can't run the code here. Here it is the message:" Error
Something went wrong. Please try again."

Sign in to comment.

Answers (1)

DGM
DGM on 9 Mar 2022
Three things:
  1. How are you calling the function? This file contains code prior to the function header, so it's not a function file. It's a script with a local function. If you want to use it as a script, it needs to be called within the script, prior to the function header. If you want to use it externally as a function file, remove everything prior to the function header.
  2. Close the function with an end statement.
  3. The given .mat files don't have the same filename as what the code is looking for.
  1 Comment
Pul
Pul on 9 Mar 2022
Thank you very much.
1.It is a code I found on Github and it starts like that. I just needed to run it and then comparing it with my data.
3. I noticed it only here: "load('baymbt_params_soil.mat','b_draws_final','tau2_draws_final');"

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!