フィルターのクリア

New to mablab and need some basic help!

2 ビュー (過去 30 日間)
Daniel Hodgson
Daniel Hodgson 2020 年 2 月 3 日
コメント済み: Star Strider 2020 年 2 月 3 日
I need to make a dice with riged odds and plot the results in a bar chart. The dice and the riged odds part gives me the result im seeking, but i dont know how to convert these anwsers into a bar chart seeming my x- values keeps on changing value.
clc, clear all
for index=(1:1000)
x=randi([1,13]);
if x==1
x=5
elseif 2<=x && x<=5
x=randi([1,2])
elseif 6<=x && x<=7
x=4
elseif 8<=x && x<=9
x=6
elseif 10<=x && x<=13
x=3
end
end
Thanks

採用された回答

Star Strider
Star Strider 2020 年 2 月 3 日
You might find the histogram function useful.
  6 件のコメント
Daniel Hodgson
Daniel Hodgson 2020 年 2 月 3 日
THANK YOU SO MUCH <3
This is my code, there is probaly an easier way to solve this problem. But who cares!
clc, clear all
a=1;
A=[1: a];
for i=(1:1000)
a=0
a=1+a;
x=randi([1,13]);
if x==1
x=5
elseif 2<=x && x<=5
x=randi([1,2])
elseif 6<=x && x<=7
x=4
elseif 8<=x && x<=9
x=6
elseif 10<=x && x<=13
x=3
end
A(i)=x;
a=a+1;
end
histogram(A)
Star Strider
Star Strider 2020 年 2 月 3 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (2 件)

Dave
Dave 2020 年 2 月 3 日
Consider creating an empty matrix prior to the 'for' statement. Then write the results to that matrix.
  1 件のコメント
Daniel Hodgson
Daniel Hodgson 2020 年 2 月 3 日
I have now updated by problem to 1000 rolls ofthe dice. Is there a way for matlab to put these values into the matrix and if so how?

サインインしてコメントする。


Dave
Dave 2020 年 2 月 3 日
If you haven't already solved this, search for something like "creating arrays with loops". That should give you some examples on how to proceed.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by