在 MATLAB 绘图中用特定颜色为图形上的特定点着色

Coloring specific points with specific colors on a graph in MATLAB plot

我有 "classes" 和 "inputs" 数组。两个数组的维度都是 1x2000。

在"classes"数组中,记录了"inputs"数组中数据的簇。例如,

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

当我像 plot(inputs) 一样绘制 "inputs" 数组时,我想对每个数据进行不同的着色,这些数据对应于 "classes" 数组中的特定簇。

我该如何管理?

谢谢。

最简单的解决方案是执行以下操作:

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');

您可以扩展此想法,例如遍历 类、自定义颜色排序等。 如果您想要更具体或更详细的答案,请在您的问题中添加更多信息。