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:
grpstats function and how draw 2 graph on the same figure?

Subject: grpstats function and how draw 2 graph on the same figure?

From: selim bensalah

Date: 14 Feb, 2009 10:51:02

Message: 1 of 2

Hi,
I'am working on grpstats function and I would like to draw two graph on the same figure. The first graph will be drawn in three groups (G1,G2,G3) and the second one will be drawn in only two groups (G1 and G3). When I use hold on function on matlab, the second function will be draw on the same figure but it is drawn in group G1 and G2 instead of G1 and G3.
someone can help me?
I'm thankful in advance

Subject: grpstats function and how draw 2 graph on the same figure?

From: Peter Perkins

Date: 17 Feb, 2009 15:38:46

Message: 2 of 2

selim bensalah wrote:
> Hi,
> I'am working on grpstats function and I would like to draw two graph on the same figure. The first graph will be drawn in three groups (G1,G2,G3) and the second one will be drawn in only two groups (G1 and G3). When I use hold on function on matlab, the second function will be draw on the same figure but it is drawn in group G1 and G2 instead of G1 and G3.
> someone can help me?

Selim, I assume you've given GPSTATS a grouping variable that's either integer values, or strings. The problem is that the second call to GRPSTATS doesn't "know" that although you've given it a grouping variable with "G1" and "G3", there's also a "G2", and you want it to fall between the other two. Given a grouping variable that's either integer values or strings, GRPSTATS assumes that the values in that grouping variable represent _all_ of the groups.

The solution is to use a nominal grouping variable. Compare this:

g1 = randi([1 3],50,1); x1 = randn(size(g1));
g2 = randi([0 1],50,1); g2(g2==2) = 3; x2 = randn(size(g2));
grpstats(x1,c1,.05); hold on, grpstats(x2,c2,.05); hold off

to this:

c1 = nominal(g1,{'g1' 'g2' 'g3'},[1 2 3]);
c2 = nominal(g2,{'g1' 'g2' 'g3'},[1 2 3]);
grpstats(x1,c1,.05); hold on, grpstats(x2,c2,.05); hold off

Of course, since "G2" is missing from the second plot, there's no bar from "G1" to "G3".

Hope this helps.

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