Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Replot histograms with different means?

Subject: Replot histograms with different means?

From: Gwenywar

Date: 1 Aug, 2013 13:27:10

Message: 1 of 4

Hello,

I've plotted 2 histograms in one figure and I start with both having the same mean and SD, so they completely overlap.

I then want to plot figure 2, where I increase the mean of 1 histogram by 50%.

Is there a way I can tell matlab to plot the same as in figure 1 but with a different mean for one histogram without copy and paste all the commands from figure 1?

So something like:

figure2:
recreate(figure1)
now mean of Hist2 is 150


Thanks for your help!!

Subject: Replot histograms with different means?

From: dpb

Date: 1 Aug, 2013 13:40:58

Message: 2 of 4

On 8/1/2013 8:27 AM, Gwenywar wrote:
> Hello,
> I've plotted 2 histograms in one figure and I start with both having the
> same mean and SD, so they completely overlap.
> I then want to plot figure 2, where I increase the mean of 1 histogram
> by 50%.
>
> Is there a way I can tell matlab to plot the same as in figure 1 but
> with a different mean for one histogram without copy and paste all the
> commands from figure 1?
> So something like:
> figure2:
> recreate(figure1)
> now mean of Hist2 is 150
>
You can

a) save the previous commands to a script or function file and then be
able to recreate on demand. You can modify the function to alter the
data of any one or both as desired. Or,

b) if the first is still available, use copyobj to make a copy in a new
figure and modify it. You can get() the data and set() it modified by
the new mean or choose many other ways to make the modification.

But, yes, there is no function already existing that will do it all
automagically altho as noted you can make it reasonably painless (after
the first time, of course--you do have to do that work once).

Subject: Replot histograms with different means?

From: Kevin Hellemans

Date: 1 Aug, 2013 14:08:07

Message: 3 of 4

If I can assume you have your original data, the code below will work. Otherwise I refer to the previous posters reply.

% Generate histogram data with mean 100
r= randn(10000,1)+100;

% calculate original histogram
xcenters = 80:160;
[n1,x1] = hist(r,xcenters);

% calculate histogram with offset +1
[n2,x2] = hist(r+mean(r)*0.5,xcenters);

% Make bargraph
XData = x1;
YData = [n1;n2];
bg = bar(XData',YData')
legend({'Original','Offset'})

Hope this helps!

Subject: Replot histograms with different means?

From: Gwenywar

Date: 5 Aug, 2013 09:25:06

Message: 4 of 4

Great, thanks for your help! I saved it as a function and it works now!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us