Import and plot file with day and time information
조회 수: 4 (최근 30일)
이전 댓글 표시
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
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
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
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
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 Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!