在 MATLAB 中绘制具有不同颜色的多列

Plot multiple columns with different colors in MATLAB

我有一个 372x15 矩阵。我试图以这样的方式绘制图表,即第 1-14 列将位于 x 轴上,每列颜色不同,而第 15 列将被视为 y 轴。例如,带有 (x1, y)、(x2, y) 等等的图,其中 x1 是第 1 列中的所有数据点。这是一个简单的散点图。我如何在 MATLAB 上执行此操作?

一个简单的方法就是使用 plot(A(:,1:end-1), A(:,end), '.')。这是一个例子:

A = [(1:14)-.6*rand(372,14) ((1:372).'+rand(372,1))]; % example A. Uses implicit expansion
plot(A(:,1:end-1), A(:,end), '.') % do the plot
axis tight % optionally make axis limits tight

以上循环the 7 predefined colors。如果您喜欢自定义颜色,请在调用 plot 之前设置轴的 'ColorOrder' 属性,并使用 hold on 以防止 Matlab 重新设置它:

clf % clear figure
cmap = autumn(size(A,2)); % example colormap
set(gca, 'ColorOrder', cmap); % set that colormap
hold on % needed so that the colormap is not automatically reset
plot(A(:,1:end-1), A(:,end), '.')
axis tight

您可以指定不同的标记或标记大小;参见 plot's documentation