MATLAB:n 天的时间序列图

MATLAB: Time series plot for n days

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

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

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

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

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,y(:,n),'.-'); 
    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