Matlab中的条件散点 [英] conditional scatter in matlab

查看:122
本文介绍了Matlab中的条件散点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Matlab(2D)中散射,其中标记的颜色以第三列为条件.我可以使用循环并保持,但是也许有一个更简单的方法.

Is it possible to scatter in matlab (2D) where the color of the marker is conditioned on a third column. I can use loops and hold on but maybe there is a simpler way.

基督徒

推荐答案

scatter的第四个参数允许您指定颜色.来自文档:

The fourth argument to scatter allows you to specify a colour. From the documentation:

散点图(X,Y,S,C)

scatter(X,Y,S,C)

...

C确定每个标记的颜色.当C是与X和Y长度相同的向量时,C中的值线性映射到当前颜色图中的颜色.当C是1×3矩阵时,它将标记的颜色指定为RGB值.如果您在散点图中有3个点,并且希望让颜色成为色图的索引,则C应该是3比1的矩阵. C也可以是颜色字符串(有关颜色字符串说明符的列表,请参见ColorSpec).

C determines the color of each marker. When C is a vector the same length as X and Y, the values in C are linearly mapped to the colors in the current colormap. When C is a 1-by-3 matrix, it specifies the colors of the markers as RGB values. If you have 3 points in the scatter plot and wish to have the colors be indices into the colormap, C should be a 3-by-1 matrix. C can also be a color string (see ColorSpec for a list of color string specifiers).

尝试类似的东西:

X = rand(1, 10);
Y = rand(1, 10);
colour = randi(3, 1, 10)

colour =

 2     1     3     1     3     1     2     2     3     1

scatter(X, Y, [], colour, 'filled');

如果您的数据集很大,并且几乎没有不同的颜色类别,那么我倾向于使用绘制是一种更快的绘制方法.

If your datasets are large, and there are few different colour categories, I tend to find that using plot with hold on is a faster way to plot.

这篇关于Matlab中的条件散点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆