Error using ==> histc; Edge vector must be monotonically non-decreasing.
6 次查看(过去 30 天)
显示 更早的评论
So I will admit up front that I am terrible at coding, but I have run into an issue that I haven't been able to solve. The error referenced in the title seems to occur about 1/10000 runs of the simulation (which in turn means 1 in a million uses of the algorithm). I believe I know where in the code the error arises (if I comment out the block of code I no longer receive the error), but not what the error means or how to remedy it.
The error occurs in the following block of code:
[Xn,Yn] = selection(X,Y,sI,sB,r,u,N);
%%Expected Genotypes
XAXA = Xn(1,1)*Xn(2,1);
XAXa = Xn(1,2)*Xn(2,1) + Xn(1,1)*Xn(2,2);
XaXa = Xn(1,2)*Xn(2,2);
XAYA = Xn(1,1)*Yn(1);
XAYI = Xn(1,1)*Yn(2);
XAYa = Xn(1,1)*Yn(3);
XaYA = Xn(1,2)*Yn(1);
XaYI = Xn(1,2)*Yn(2);
XaYa = Xn(1,2)*Yn(3);
H1 = [XAXA,XAXa,XaXa];
H2 = [XAYA,XAYI,XAYa,XaYA,XaYI,XaYa];
%%Actual Genotypes
G1 = mnrnd(N/2,H1)/(N/2);
G2 = mnrnd(N/2,H2)/(N/2);
G = [G1,G2];
But, I believe it is a result of something happening in the function "selection". Particularly, in this segment of the code:
%Allele frequencies of gametes produced in the current generation before mutations
Xt(1,1) = (G_now(1)+0.5*G_now(2))/sum(G_now(1:3)); %XA in eggs
Xt(1,2) = (0.5*G_now(2)+G_now(3))/sum(G_now(1:3)); %Xa in eggs
if(Xt(1,2) < 1e-8)
Xt(1,2) = 0;
end
Xt(2,1) = (G_now(4) + G_now(5) + (1-r)*G_now(6) + r*G_now(7))/sum(G_now(4:9)); %XA in sperm
Xt(2,2) = (r*G_now(6) + (1-r)*G_now(7) + G_now(8) + G_now(9))/sum(G_now(4:9)); %Xa in sperm
if(Xt(2,2) < 1e-8)
Xt(2,2) = 0;
end
Yt(1) = (G_now(4) + r*G_now(6)+(1-r)*G_now(7))/sum(G_now(4:9)); %YA in sperm
Yt(2) = (G_now(5) + G_now(8))/sum(G_now(4:9)); %YI in sperm
Yt(3) = (G_now(9) + (1-r)*G_now(6) + r*G_now(7))/sum(G_now(4:9)); %Ya in sperm
if(Yt(3) < 1e-8)
Xt(3) = 0;
end
%Allele frequency of gametes produced in the current generation after mutations
Xn(1,1) = Xt(1,1) + N*u*Xt(1,2);
Xn(1,2) = Xt(1,2) - N*u*Xt(1,2);
Xn(2,1) = Xt(2,1) + N*u*Xt(2,2);
Xn(2,2) = Xt(2,2) - N*u*Xt(2,2);
Yn(1) = Yt(1) + N*u*Yt(3);
Yn(2) = Yt(2);
Yn(3) = Yt(3) - N*u*Yt(3);
Previously, I had frequencies for Xt(1,2), Xt(2,2), and Yt(3) defined as 1 minus their respective complements. For whatever reason, that produced more infrequent errors than the code as it is currently shown. Basically, I have no clue what is wrong.
采纳的回答
Walter Roberson
2013-8-21
You do not have any obvious use of histc() in the code you show. Is the error being reported as part of one of the calls to mnrnd() ?
The error means that when histc() is called, the bin list given must not have any element that is less than a previous element, but elements equal to the immediately previous element of the bin list are accepted.
7 个评论
Walter Roberson
2013-8-21
histc itself is happy with a bin vector of [0 0.946692712763803 1 1 1], so if histc complained then at least one of the "1" must have been slightly different from true 1.0
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!