簡體   English   中英

在MATLAB圖中以特定顏色為特定點着色

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

我有“類”和“輸入”數組。 兩個陣列的尺寸均為1x2000。

在“類”數組中,記錄“輸入”數組中的數據簇。 例如,

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

當我繪制諸如plot(inputs)類的“ inputs”數組時,我想為每個與“ classs”數組中的特定簇相對應的數據分別上色。

我該如何處理?

謝謝。

最簡單的解決方案是執行以下操作:

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

您可以擴展這個想法,例如遍歷類,自定義顏色順序等等。 如果您想要更具體或更詳細的答案,請在問題中添加更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM