从X轴文本文件中创建图表,其中X轴是日期,毫秒精度,Y是值 [英] creating graph from text file where axis X is date with millisecond precision and Y is value

查看:172
本文介绍了从X轴文本文件中创建图表,其中X轴是日期,毫秒精度,Y是值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的文本文件:

  10:00:15:956 0,0155260005803643 
10: 00:21:968 0,0155280030632315
10:00:21:968 0,0155270018379389
10:00:21:968 0,0155260006126463
10:00:22:069 0,0155239981620611
10:00:22:090 0,0155249993873537

第一列是毫秒精度的时间第二列是价值。
我需要绘制图形,其中轴X是时间轴Y是值。


  • 我应该使用什么函数来读取文件? dlmread,textscan,importdata?

  • 如何强制matlab识别时间?我可以写任何需要的格式(10:00:22:090或10.00.22.090或其他任何东西),但我需要matlab来正确理解和处理时间标签。例如,10:00:22:090和10:00:23:090之间的差距是一秒,在轴X上的这些标签之间应该使用这个间隔。我想看到X轴上的时间,而我不想把时间转换成一些不可读的int值或类似的东西(例如从10.00.00开始经过的毫秒数)。

    解决方案

    您可以在几秒钟内完成,并在图中使用 datatics 。注意我有一个快速修复在第二列中处理逗号。可能你不需要它。

      f = fopen('foo.txt'); 
    data = textscan(f,'%f:%f:%f:%f%f,%f');
    fclose(f);

    %hh:min:sec:millisec
    secvec = [60 * 60 60 1 1e-3];
    x = [data {1:4}] * secvec';

    flvec = [1 1e-16];
    y = [data {5:6}] * flvec';

    xindays = x /(24 * 60 * 60);
    plot(xindays,y,'x');
    datetick('x','HH:MM:SS');


    I have text file like that:

    10:00:15:956 0,0155260005803643
    10:00:21:968 0,0155280030632315
    10:00:21:968 0,0155270018379389
    10:00:21:968 0,0155260006126463
    10:00:22:069 0,0155239981620611
    10:00:22:090 0,0155249993873537
    

    First column is time with millisecond precision and second column is value. I need to draw graph where axis X is time and axis Y is value.

    • What function should I use to read file? dlmread, textscan, importdata?
    • How to force matlab to recognize "time"? I can write time at any needed format (10:00:22:090 or 10.00.22.090 or anything else), but I need matlab to understand and process time labels correctly. For example difference between 10:00:22:090 and 10:00:23:090 is one second and exactly that interval should be use between these labels on axis X. I want to see "time" on axis X and I do not want to convert time to some "unreadable" int values or something like that (number of milliseconds elapsed from 10.00.00 for example.)

    解决方案

    You can have it in seconds and use datatics in plots. Note I have a quick fix to deal with comma in the second column. Probably you do not need it.

    f = fopen('foo.txt');
    data = textscan(f, '%f:%f:%f:%f %f,%f');
    fclose(f);
    
    % hh:min:sec:millisec
    secvec = [60*60 60 1 1e-3];
    x = [data{1:4}] * secvec';
    
    flvec = [1 1e-16];
    y = [data{5:6}] * flvec';
    
    xindays = x / (24*60*60);
    plot(xindays, y, 'x');
    datetick('x', 'HH:MM:SS');
    

    这篇关于从X轴文本文件中创建图表,其中X轴是日期,毫秒精度,Y是值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆