generating 10 samples from a binomial using a fair dice.
显示 更早的评论
clc
clear all
format compact
rng(970,'v4')
U=[];
X=[];
R = rand(10,1) % generate a sample in Unif(0,1)
P = [1/6,2/6,3/6,4/6,5/6,1];
js = [1:6]; F = cumsum(P); disp(F)
if R < 1/6
x=1
X=[Xx]
U=[UR];
else if R >= 1/6 & R <2/6
x=2
X=[Xx]
U=[UR];
else if R >= 2/6 & R < 3/6
x=3
X=[Xx]
U=[UR];
else if R >= 3/6 & R < 4/6
x=4
X=[Xx]
U=[UR];
else if R >= 4/6 & R < 5/6
x = 5
X=[Xx]
U=[UR];
else if R >=5/6 & R < 1
x=6
X =[Xx]
U=[UR];
end
end
end
end
end
end
i wanted my outcome to come out in terms of 1,2,3,4,5,6 when my x are these values
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!