|
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.
|