why is my results coiming out as a single 0 while using matlab

1 回表示 (過去 30 日間)
oshomah kanoba
oshomah kanoba 2015 年 3 月 1 日
回答済み: Mischa Kim 2015 年 3 月 1 日
R = rand (10,1)% generate a sample in Unif(0,1) P = 0.5 N = 10 if R < P fprintf = 1 else fprintf = 0 end

採用された回答

Mischa Kim
Mischa Kim 2015 年 3 月 1 日
R is a vector, P is a scalar. Do you mean to do
R = rand (10,1)% generate a sample in Unif(0,1)
P = 0.5; N = 10;
for ii = 1:numel(R)
if R(ii) < P
fprintf = 1
else
fprintf = 0
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVerify Generated Code and Deployed Code Artifacts についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by