필터 지우기
필터 지우기

Help please simulation of gibbs sampling isempty function?

조회 수: 2 (최근 30일)
arkedia
arkedia 2013년 2월 9일
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에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by