Import and plot .CSV with timestamp

12 views (last 30 days)
I have a csv file along with timestamp and i cannot manage to plot my data correctly. My file is comma delimited, first date, then time and 3 different sensor values.. I can plot sensor values as datapoints but i need also the time.. Anyone eho can help?
  2 Comments
Guillaume
Guillaume on 7 Nov 2018
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.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 7 Nov 2018
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});
  15 Comments
Guillaume
Guillaume on 8 Nov 2018
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})
Ancalagon8
Ancalagon8 on 8 Nov 2018
It worked perfectly @Guillaume thank you for your time!

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!