简体   繁体   English

在MATLAB图中以特定颜色为特定点着色

[英]Coloring specific points with specific colors on a graph in MATLAB plot

I have "classes", and "inputs" array. 我有“类”和“输入”数组。 Both of arrays' dimensions are 1x2000. 两个阵列的尺寸均为1x2000。

In "classes" array, the clusters of data in "inputs" array are recorded. 在“类”数组中,记录“输入”数组中的数据簇。 For instance, 例如,

classes = [5, 2, 4, 3, 5, ...]
inputs = [5.234, 6.345, 4.342, 2.532, 5.345, ...]

When I plot "inputs" array like plot(inputs) , I want to differently color each data which correspond to the specific clusters in "classes" array. 当我绘制诸如plot(inputs)类的“ inputs”数组时,我想为每个与“ classs”数组中的特定簇相对应的数据分别上色。

How can I manage this? 我该如何处理?

Thanks. 谢谢。

The simplest solution is to do something like: 最简单的解决方案是执行以下操作:

x = 1:numel(inputs);
plot(x(classes == 1), inputs(classes == 1), '.b', 
     x(classes == 2), inputs(classes == 2), '.g', 
     x(classes == 3), inputs(classes == 3), '.r');

You can expand on this idea, such as looping over the classes, customizing color ordering, and more. 您可以扩展这个想法,例如遍历类,自定义颜色顺序等等。 Please add more information to your question if you want a more specific or detailed answer. 如果您想要更具体或更详细的答案,请在问题中添加更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM