Borrar filtros
Borrar filtros

Help please simulation of gibbs sampling isempty function?

2 visualizaciones (últimos 30 días)
arkedia
arkedia el 9 de Feb. de 2013
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

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Feb. de 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.

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by