-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmbe_concChains.m
40 lines (35 loc) · 1.02 KB
/
mbe_concChains.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function mcmcChainOut = mbe_concChains(mcmcChain)
%% mbe_concChains
% Concatenate several MCMC chains into one.
%
% INPUT:
% mcmcChain
% is a structure containing one structure for every MCMC chain.
% This is the default output of matjags.
%
% OUTPUT:
% mcmcChainOut
% one structure with fields for every parameter
%
% EXAMPLE:
% mcmcChainOut = mbe_concChains(mcmcChains);
% Nils Winter ([email protected])
% Johann-Wolfgang-Goethe University, Frankfurt
% Created: 2016-03-15
% Version: v1.2 (2016-04-12)
% Matlab 8.1.0.604 (R2013a) on PCWIN
%-------------------------------------------------------------------------
% get names
names = fieldnames(mcmcChain(1,1));
% preallocate
for indNames = 1:numel(names)
mcmcChainOut.(names{indNames}) = [];
end
% concatenate chains
for indNames = 1:size(names,1)
for indChain = 1:size(mcmcChain.(names{1}),2)
mcmcChainOut.(names{indNames}) = [mcmcChainOut.(names{indNames});...
mcmcChain.(names{indNames})(:,indChain,:)];
end
end
end