clear all
%heads>=0.5 %tails<0.5
for i=1:500
coin=rand(1,2);
A=[coin];
toss=1;
while coin(1)<.5
coin=rand(1,2);
B=[coin];
toss=1+tossr;
A=[A;B];
C=[toss];
end
fprintf('Number of toss to obtain head %.0f \n',toss)
end
如何制作所有折腾频率的矢量?
我想制作所有投掷的频率表
答案 0 :(得分:0)
检查这是一个更简单的解决方案:
clear; clc; close;
toss=0;
Tossvector=[];
%heads>=0.5 %tails<0.5
for i=1:500
coin=rand();
if coin <.5
toss=toss+1;
Tossvector=horzcat(Tossvector,toss);
end
if coin >.5
fprintf('Number of toss to obtain head %.0f \n',toss)
toss=0;
end
end
答案 1 :(得分:0)
使用def my_params
required_attrs = %w{lat lng}
missing_params = required_attrs.select do |key|
params.has_key?(key)
end
missing_params.empty? ? params : raise(RuntimeError, "missing params: #{missing_params.join(",")}")
end
randi