- 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.
- Close the function with an end statement.
- The given .mat files don't have the same filename as what the code is looking for.
Why am I not able to plot this?
1 view (last 30 days)
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.
% load appropriate model
error('TModel not recognized - choices are "T" and "T0"');
error('Type not recognized - choices are "soil" and "lake"');
% 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 using BayMBT0, truncate at T < 0
output.ens(output.ens < 0) = NaN;
output.T = prctile(sort(output.ens,2),[2.5 50 97.5],2);
DGM on 9 Mar 2022