Help please simulation of gibbs sampling isempty function?

2 visualizzazioni (ultimi 30 giorni)
i make a simulation to a gibbs sampling algorithm and the following code is part of the simulation :
mamodel=@(x)find(ismember(x(:,2:end),[1 0 0 0 0],'rows'))
if~isempty(a)
macount=a(mamodel(a),:)
else
macount=zeros(1,size(a,2))
end
h(i,:)=(macount)
the first line is to find a certain row from simulation results the problem is when this row is not in the results the smulation stops because the result is Empty matrix: 0-by-6 , i tried isempty function and also the simulation stops!! i want to make the simulation ignore the results and continue to next step

Risposte (1)

Walter Roberson
Walter Roberson il 10 Feb 2013
When I look at your anonymous function it appears to me that it could potentially return a variable number of results, leading to macount being an array rather than a column vector. You would then get a dimension mismatch when assigning it to h(i,:)
Since you need a result which is the same number of rows as h has, use zeros(1,size(h,2)). Unless, that is, you did not predefine h, in which case for your first execution, you would not have an "h" to take the size of.

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by