-1

我是 MATLAB 中的 Stats Package 的新手,我试图在向量 A 和 B 之间制作散点图(所以 A vs B),但我想用一种颜色显示 A 值,用另一种颜色显示 B 值。

例如 A = [1 2 3 4];B = [1.2 2.2 3.2 4.2];

我不想使用“scatter”和“hold on”等,并且想了解分组数据以在“gscatter”中使用。我试图阅读帮助,无法理解。所以一个小例子将非常有用(带注释)。

谢谢!

4

1 回答 1

2

First of all, you have to figure out your coordinates. If you say you want to plot Avs Bthat gives you 4 pairs - and Awould equal Xin such a plot, just as B would equal Y.
This, however, raises the question of how to group them to get individual colors. It makes no sense to say, "I want A to be red and B to be blue" - because they are part of the same symbol. Therefore, either A and B both have to be Y, which raises questions about what X should be, or the grouping has to be different.
Here's an explanation on how gscatter works, you can then figure out the grouping:

gscatter(A,B,group,CLR,SYM);

First, CLR is a string variable containing colors and SYM is a string variable containing symbols. The length of CLR and SYM has to correspond to the different elements in group.
group is a grouping variable. These are very flexible.
Let's look at an easy example:
Assume, that the first two pairs of A and B are a group, as well as the second. We can then specify group as:

group = [0 0 1 1];

With

CLR = 'rb';
SYM = 'xo';

gscatter(A,B,group,CLR,SYM);

Will produce a plot that has two data sets, one consisting of red x-es and the other of blue circles.

于 2013-07-03T20:53:37.210 回答