【问题标题】:Time and temperature axes that are sorted by plot function in matabmatlab中按绘图函数排序的时间和温度轴
【发布时间】:2017-07-13 15:29:45
【问题描述】:

我有一个 ph 计采集,分为 3 天。我已经提取了每天hh:mm:ss 格式的时间。这意味着第一天从12:3214:39,第二天从14:1216:17 等。温度相同(从 23 到 24°,从 22 到 24 等 2 天)。

现在我必须绘制数据(phwrtTTime),但如果我连接 3 次和 T 向量,或者为每个时间和温度创建一个单列向量, MATLAB 自动对绘图的x 轴的值进行递增排序。我需要沿轴保留原始值(这意味着值必须是 14:32 14:33 14:34 12:24 12:25 等等,温度也是如此),因为我必须保持采集时的数据。

【问题讨论】:

标签: matlab plot graph temperature


【解决方案1】:

将您的 hh:mm:ss 转换为 datenum - 可能需要添加日、月、年,以便按照您想要的正确顺序。然后你可以将你的刻度设置为 HH:MM:SS 或秒或任何你需要的。 看这里: https://www.mathworks.com/help/matlab/ref/datetick.html

【讨论】:

    【解决方案2】:

    从 2014b 开始,您可以使用datetime

    选择记录的实际日期,或相隔一天的任意日期,并将日期部分分配给您的数据,例如

    % Create 3 random time arrays of the format 'hh:mm:ss'
    t = [randi([10,14], 10,1), randi([0,59], 10,1), randi([0,59], 10,1)];
    T1 = [num2str(t(:,1), '%02i'), repmat(':', 10, 1), num2str(t(:,2), '%02i'),repmat(':', 10, 1), num2str(t(:,3), '%02i')];
    t = [randi([10,14], 10,1), randi([0,59], 10,1), randi([0,59], 10,1)];
    T2 = [num2str(t(:,1), '%02i'), repmat(':', 10, 1), num2str(t(:,2), '%02i'),repmat(':', 10, 1), num2str(t(:,3), '%02i')];
    t = [randi([10,14], 10,1), randi([0,59], 10,1), randi([0,59], 10,1)];
    T3 = [num2str(t(:,1), '%02i'), repmat(':', 10, 1), num2str(t(:,2), '%02i'),repmat(':', 10, 1), num2str(t(:,3), '%02i')];
    
    % Convert to dates on consecutive days
    D1 = datetime(strcat('2000-01-01-', T1), 'inputformat', 'yyyy-MM-dd-HH:mm:ss');
    D2 = datetime(strcat('2000-01-02-', T1), 'inputformat', 'yyyy-MM-dd-HH:mm:ss');
    D3 = datetime(strcat('2000-01-03-', T1), 'inputformat', 'yyyy-MM-dd-HH:mm:ss');
    
    % Plot
    data = rand(30,1);
    plot([D1, D2, D3], data);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多