【问题标题】:MATLAB Plotting a monthly data on a daily axisMATLAB 在日轴上绘制月度数据
【发布时间】:2013-07-07 08:23:47
【问题描述】:

我有一个在 x 轴上有 528 个点的图。 x 轴由 mmm yyyy 标记。我想在上面绘制数据,但数据是月度形式的。我想获取每个月度数据点,并在月初将其绘制为一个点。

% Axis and plot
t = 731:1258; % 20120101 to 20130611
y = reshape(dataPoint_Anom1x1(:,:,731:end),[],1); % Size 528x1
x = datenum(2009, 12, 31) + t; % Convert t into serial numbers

plot(x, y); % Plot data

hold on

下面的部分是我遇到的问题。 dataPoint_Clim1x1 的大小为 12x1。 (1,1) 对应 1 月,(2,1) 对应 2 月等。我需要在 2012 年 1 月和 2013 年 6 月之间的每个月初将对应月份的气候点绘制为一个点。

%%%% Plot climatology on the same graph
dataClim_1x1 = dataClim(u,v,:); % Array that only contains points 1 degree away from 72.5E and 67.25S
B = mean(dataClim_1x1);  % Average along the column
dataPoint_Clim1x1 = mean(B,2); % Average along the row

x_dataClim = ???
y_dataClim = reshape(dataPoint_Clim1x1, [],1); % Change dataPoint_Clim1x1 into a 1 column matrix 


plot(x_dataClim,y_dataClim) % y_dataClim is only 12x1. 

所以上面的 plot 命令是错误的。我是否只需要以某种方式设置 x 轴,以便它以某种方式每个月用 datenum 绘制?不过我不想使用辅助轴。

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    我认为您只需要定义点的 x 坐标

    x_dataClim = datenum(2011, 1:12, 1);
    

    这会生成“本月的第一天”:

    >> datestr(x_dataClim)
    
    ans = 
    
    01-Jan-2011
    01-Feb-2011
    01-Mar-2011
    01-Apr-2011
    01-May-2011
    01-Jun-2011
    01-Jul-2011
    01-Aug-2011
    01-Sep-2011
    01-Oct-2011
    01-Nov-2011
    01-Dec-2011
    

    很酷的是你实际上可以“进入明年” - 所以

    >> datestr(datenum(2011, 11:14, 1)) 
    
    ans =
    
    01-Nov-2011
    01-Dec-2011
    01-Jan-2012
    01-Feb-2012
    

    【讨论】:

      【解决方案2】:

      这是我最终做的:

      x = datenum(2011,1:30,1); % 30 months of data (2 and 1/2 years)
      y_dataClim = reshape(dataPoint_Clim1x1, [],1); % Change dataPoint_Clim1x1 into a 1 column matrix 
      y = cat(1, y_dataClim, y_dataClim, y_dataClim(1:6,:));
      scatter(x,y, 50,'fill'); % Plot scatter plot
      

      【讨论】:

        猜你喜欢
        • 2021-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-04
        • 2015-08-24
        • 2014-03-14
        • 1970-01-01
        • 2012-10-17
        相关资源
        最近更新 更多