Using Histogram to create a figure with multiple data sets

25 views (last 30 days)
Michelle Jackson
Michelle Jackson on 30 Sep 2021
Commented: Michelle Jackson on 30 Sep 2021
Hello! I'm new to MATLAB and am learning how to plot data. I have data stored in multiple double arrays. I am trying to plot them all in a histogram, where each bin can store the values in that range from the multiple doubles. My issue that i am having is that the code below overlays multiple histograms over top of each other rather than group them into one histogram. I hope this makes sense. I appreciate any help.
What I have so far is this (after I have imported my data, i'll skip that section)
a = Initial(1).red;
b = Initial(1).green;
c = Initial(2).red;
d = Initial(2).green;
e = Initial(4).red;
f = Initial(4).green;
NumBins = 20;
histogram(a/b,NumBins,'FaceColor','black'); hold on
ylim([0 20]);
set(gca, 'XScale', 'log');
Michelle Jackson
Michelle Jackson on 30 Sep 2021
Oh wow okay thank you I see, yes I wasn't using the divide function correctly. I tried out that method but now I'm getting the error "Error using horzcat. Dimensions of arrays being concatenated are not consistent." I should add that the arrays are not the same length (a divided by b is 25x1 double and c divided by d is 29x1 double) is that the issue?

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 30 Sep 2021
One possibility would be to use histcounts to get the bin counts (instead of histogram to plot the bins directly), and then a stacked or grouped bar chart for the plotting of those counts.
  1 Comment
Michelle Jackson
Michelle Jackson on 30 Sep 2021
Thank you, I guess I could use histcounts and then use the bar function to plot them on top of eachother in each bin. I was just hoping there was an easy fix using histogram!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!