Import and plot file with day and time information

5 ビュー (過去 30 日間)
Ancalagon8
Ancalagon8 2018 年 11 月 7 日
編集済み: Ancalagon8 2025 年 1 月 6 日
I have a file and i cannot manage to plot my data correctly. I can plot values as datapoints but i need also the time.. Anyone who can help?
  1 件のコメント
Guillaume
Guillaume 2018 年 11 月 7 日
An actual file instead of a picture of it would be a lot more useful for us to test.
i cannot manage to plot my data correctly. To tell what you did wrong we need to know what you did.

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2018 年 11 月 7 日
I'm not sure what you're doing wrong since you haven't shown us what you're doing. The following may be what you're after:
t = readtable('data3.csv');
t.datetime = t.(1) + t.(2); %merge date and time into one variable
plot(t.datetime, t{:, 3:5});
  7 件のコメント
Guillaume
Guillaume 2018 年 11 月 8 日
Well, then it is not meant to be the same time! Yes, some samples are at the second, but the fraction of second would be different. Unfortunately, that information is not embedded in your text file. The best would be to fix whatever created these text files so that it writes the sub-second information.
There are many ways you could fix this depending on how robust you want it to be. If we assume that all the samples in one text file are all continuous and acquire at a rate of 125 Hz then a simple way to solve the problem is to cumulatively add 1/125 second to the timing of the 1st sample (thus completely ignoring the embedded timing of the remaining samples). If that is acceptable, then:
t.datetime = datetime(strcat(t{1, 1}, {' '}, t{1, 2}) + ... %timing of 1st sample
seconds(1/125) * (0:height(t)-1)'; %cumulatively add 1/125 second to timing of each sample
Guillaume
Guillaume 2018 年 11 月 8 日
Well, most likely the error you actually received was Invalid Expression as I forgot a closing bracket. You must have added the bracket in the wrong place.
t.datetime = datetime(strcat(t{1, 1}, {' '}, t{1, 2})) + ... %timing of 1st sample
seconds(1/125) * (0:height(t)-1)'; %cumulatively add 1/125 second to timing of each sample
Or since you don't really care about the actual acquisition time of the samples, you could simply ignore the time information from the text file and do:
plot(seconds(1/125) * (0:height(t)-1), t{:, 3:5})

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by