Question about how to put several values in one histogram
1 view (last 30 days)
Show older comments
I was writing the code for the rock paper scissors game, the last step is to graph the results (i.e player win times, computer win times, and draw times). The number I got for those three are 3,4,3. The histogram part I did as following:
stats_data = [user_win_time,draw,comp_win_time];
figure
stats_plot = histogram(stats_data);
% And the graph I got is attached

0 Comments
Accepted Answer
Chunru
on 22 Sep 2021
You should not use histogram. You should use bar:
bar([3 4 3])
set(gca, 'XTickLabel', ["Player" "Computer" "Draw"])
More Answers (1)
Viranch Patel
on 22 Sep 2021
You can do something like this.
X = categorical({'user win time','draw','computer win time'});
X = reordercats(X,{'user win time','draw','computer win time'});
Y = [3 4 3];
h = bar(X,Y);
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!