Storing a Matrix Output in a matrix
Show older comments
%% I am running the following code but having some error:
prevalence=zeros(iters,1+max(data.t));
for i=1:iters
% copy existing parameter vector
proposal=theta;
% Generate a new proposal for epsilon
proposal=normrnd(theta(1),sigma);
% check proposal is in range
if proposal(1)>0
% calculate log acceptance ratio (may be bigger than 1)
lar = logLikelihoodSIR2(proposal,data,N) - logLikelihoodSIR2(theta(1),data,N);
% don't forget the prior ratio!
lar = lar + logPrior(proposal) - logPrior(theta(1));
% generate a random number between 0 and 1;
u = unifrnd(0,1);
% accept if lar>log(u) iff ap>u
if lar>log(u)
% the proposal becomes the new value of theta
theta=proposal;
accept=accept+1;
else
reject=reject+1;
end
else
% automatically reject outside the range for beta (as it has prior
% density zero).
reject=reject+1;
end
% store parameters for output every iteration (at the moment)
stored(i,:)=theta;
% recalculate and store trajectory for output
Numgroups = 5;
N = [600000 800000 1000000 1500000 6000000];
sigma = [0.01 0.05 0.2 0.3 0.4];
para = struct('N',N,'H',0.25,'da',0.3,'tau',0.15,'gamma',0.1, ...
'epislon',theta(1),'Numgroups',Numgroups,'sigma',sigma,'q_s',0.05, ...
'q_w',0.2, 'q_o',0.5,'q_h',1/4,'phi_t',0.25,'theta',0.45);
S = [600000 800000 1000000 1500000 6000000] - [1 zeros(1,Numgroups - 1)];
%Define initial conditions as a structure
ICs = struct('S',S,'E_f',[1 zeros(1,Numgroups - 1)],'E_sd',zeros(1,Numgroups), ...
'E_su',zeros(1,Numgroups),'E_q',zeros(1,Numgroups),'D_f',zeros(1,Numgroups), ...
'D_sd',zeros(1,Numgroups),'D_su',zeros(1,Numgroups),'D_qf',zeros(1,Numgroups), ...
'D_qs',zeros(1,Numgroups),'U_f',zeros(1,Numgroups),'U_s',zeros(1,Numgroups), ...
'U_q',zeros(1,Numgroups),'N',N);
Classes=ODE_agemodelkeelMCMC(para,ICs,min(data.t),max(data.t));
prevalence(i,:) = Classes.E_f./N;
end
My question is in the BOLDEN PART.
Classes.E_f./N is an (844 by 5) matrices which is what I want.
Prevalence(i,:) is a (1 by 844) which means that I want to store each iteration of Classes.E_f./N into the prevalence matrix I have pre-defined. But I am running into error : Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I know the sizes differs but I don't know how better to handle this.
Accepted Answer
More Answers (0)
Categories
Find more on Particle & Nuclear Physics 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!