MATLAB:n 天的时间序列图

问题描述

我正在尝试绘制散点图,x 轴以 0.25 的步长占据 5 到 15 的范围,y 轴占据 41 个随机数据,持续 20 天。

clc
clear
x = 5:0.25:15;
y = rand(41,20);

如何在 MATLAB 上实现散点图,从而使 x 范围适用于所有 20 列?

解决方法

您是否想要一个带有连接线的散点图,以便您可以识别不同的数据集?在这里,我使用了相同的 for 循环方法并使用 hold on 保持绘图。在行 plot(t,y(:,n),'.-'); 中,术语 '.-' 用于指示在数据点处用连接的线和点绘制数据。正如上面针对随机数据集所做的最佳拟合多项式所指出的那样,即使根本没有也不会揭示非常有用的信息。

Scatter Plot with Connected Lines

clf;
Start_Time = 5;
End_Time = 15;
Time_Interval = 0.25;
t = (Start_Time: Time_Interval: End_Time); 
y = rand(41,20);

for n = 1:20 
    plot(t,'.-'); 
    hold on 
end

Legend_Labels = "Data 1";
for Dataset_Index = 2: size(y,2)
   Legend_Labels = [Legend_Labels "Data "+num2str(Dataset_Index)];    
end

Current_Figure = gcf;
Current_Figure.Position = [50 50 1000 400];
title("Plotting Random Data with Respect to Time");
legend(Legend_Labels,'Location','EastOutside','Orientation','vertical');
xlabel("Time (s)"); ylabel("Value");

使用 MATLAB R2019b 运行