Graph one set of data in two different colors

I have a set of data in a matrix and I wanted to create a scatter plot where if the ratio of X/Y is <4 my points were one color and if the ratio is >=4 the points would appear as another color, all on one graph. I tried
if X/Y >4
plotmatrix(X,Y,'g')
hold on
else
plotmatrix(X,Y,'b')
end
hold off

1 件のコメント

Star Strider
Star Strider 2015 年 7 月 17 日
What sizes are your ‘X’ and ‘Y’ arrays?

サインインしてコメントする。

回答 (1 件)

Mike Garrity
Mike Garrity 2015 年 7 月 17 日

0 投票

One approach is something like the following:
x = rand(1,500);
y = rand(1,500);
mask = x./y > 4;
scatter(x(mask),y(mask))
hold on
scatter(x(~mask),y(~mask))
legend('x/y > 4','x/y <= 4')
The mask variable is a logical vector which tells which of your data values fall into each of your two classes. Then you can use logical indexing to extract the elements of your data which belong to a particular class.

カテゴリ

質問済み:

2015 年 7 月 17 日

コメント済み:

2015 年 7 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by