Matlab中的条件散点

编程入门 行业动态 更新时间:2024-10-20 00:45:25
本文介绍了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中的条件散点

本文发布于:2023-07-19 08:50:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154875.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!