How to plot histogram using given data ?

15 views (last 30 days)
Safia
Safia on 23 Feb 2023
Commented: Voss on 24 Feb 2023
Hello!
I'm asking if it is possible to insert data in matlab and use them to plot histogram with different colors?
i have already used excel but i need a different form of histogram (bar forms), for example the first bar contains circles, the second contains squares,...
here is my data
Value first Second third
10 0,67 0,66 0,70
20 0,38 0,37 0,42
30 0,26 0,25 0,30
40 0,19 0,19 0,24
50 0,15 0,15 0,21
i need to see "first", "second" and "third" as function of value
Thanks in advance
  2 Comments
Adam Danz
Adam Danz on 23 Feb 2023
> is it possible to insert data in matlab and use them to plot histogram with different colors?
Yes, one set of bars will be generated for each column of data, each with a different color.
data = randn(1000,3)+[-2 2 5];
hold on
histogram(data(:,1))
histogram(data(:,2))
histogram(data(:,3))
> i need a different form of histogram (bar forms)... the first bar contains circles, the second contains squares
Not sure what this means, please elaborate or show us an image.
Safia
Safia on 24 Feb 2023
@Adam Danz hello!
this is what i get with excel ,how to plot this in matlab?

Sign in to comment.

Accepted Answer

Voss
Voss on 24 Feb 2023
% Value first Second third
M = [ ...
10 0.67 0.66 0.70; ...
20 0.38 0.37 0.42; ...
30 0.26 0.25 0.30; ...
40 0.19 0.19 0.24; ...
50 0.15 0.15 0.21; ...
];
bar(M(:,1),M(:,2:end))
  2 Comments
Safia
Safia on 24 Feb 2023
@Voss thank you very much.
It is possible to modify its form like this
Voss
Voss on 24 Feb 2023
Look into the hatchfill2 function on the File Exchange in the link shared by VBBV.

Sign in to comment.

More Answers (1)

VBBV
VBBV on 23 Feb 2023
Check the answer from the below link
May be its hatch property of the bar which should be used. It seems this is not default Matlab property for bar & histogram functions. You need to use the below custom function available from File Exchange.
  1 Comment
Safia
Safia on 24 Feb 2023
@VBBV thank you .This is what i need but at first i don't know how to plot hisotgram in matlab when i already have data

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!