Help please simulation of gibbs sampling isempty function?

2 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2013-2-10
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.

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by