Plotting data against time
Show older comments
Edit: I've added the .mat file and a code which shows what i'm trying to do.
% timex=datetime(time_orginal,'Format','dd/MM/yy HH:mm:ss:SSS') does not
% work and results in a error. Hence the loop.
for i=1:length(time_orginal)
timex(i)=datetime(time_orginal(i),'Format','dd/MM/yy HH:mm:ss:SSS')
end
plot(timex,datax)
Using the .mat file provided and this code results in the following plot:

----------------------
Hi all. I have two arrays that i'm trying to plot together. Timex is a 10x1 datetime and datax is 10x1 double.
when I do
plot(timex,datax)
I dont get what i'm after, which is date and time on x axis and data on y axis.
I dont understand why the datetime is not showing up on the x-axis. Any help is much appreciated.

the data:
timex =
18/09/21 04:32:02:000
18/09/21 04:32:02:200
18/09/21 04:32:02:400
18/09/21 04:32:02:600
18/09/21 04:32:02:800
18/09/21 04:32:03:000
18/09/21 04:32:03:200
18/09/21 04:32:03:400
18/09/21 04:32:03:600
18/09/21 04:32:03:800
and
datax =
-0.0200
-0.0200
-0.0300
-0.0200
-0.0200
-0.0200
-0.0200
-0.0300
-0.0300
-0.0300
2 Comments
Walter Roberson
on 21 Sep 2021
plot(t,x)
That involves two variables that we do not know anything about. You have told us about timex and datax but not about t and x
Andy Thor
on 21 Sep 2021
Accepted Answer
More Answers (1)
the cyclist
on 21 Sep 2021
Edited: the cyclist
on 21 Sep 2021
Works for me, when I correctly specify valid dates using the input format.
I'm guessing that your datetime is somehow messed up. It would be helpful if you uploaded your variables in a MAT file (using the paperclip icon), so we can see what you are actually working with.
timex = datetime( ...
{'18/09/21 04:32:02:000'; ...
'18/09/21 04:32:02:200'; ...
'18/09/21 04:32:02:400'; ...
'18/09/21 04:32:02:600'; ...
'18/09/21 04:32:02:800'; ...
'18/09/21 04:32:03:000'; ...
'18/09/21 04:32:03:200'; ...
'18/09/21 04:32:03:400'; ...
'18/09/21 04:32:03:600'; ...
'18/09/21 04:32:03:800'},'InputFormat','dd/MM/yy HH:mm:ss:SSS');
datax = [ ...
-0.0200;
-0.0200;
-0.0300;
-0.0200;
-0.0200;
-0.0200;
-0.0200;
-0.0300;
-0.0300;
-0.0300];
figure
plot(timex,datax)
1 Comment
Andy Thor
on 21 Sep 2021
Categories
Find more on Time Series Events 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!
