MATLAB Answers

0

plotting values with duration format

Asked by sermet on 7 Sep 2017
Latest activity Commented on by sermet on 7 Sep 2017
Accepted Answer by KL
time_array=[6 0 0;6 1 0;6 2 0;6 3 0;6 4 0;6 5 0;6 6 0;6 7 0;6 8 0;6 9 0;6 10 0;6 11 0;6 12 0;6 13 0;6 14 0;6 15 0;6 16 0;6 17 0;6 18 0;6 19 0;6 20 0;6 21 0;6 22 0;6 23 0;7 0 0];
time_format=duration(time_array,'Format','hh:mm:ss');
data=[1.37;1.4;1.8;1.3;1.35;1.31;1.2;1;1.26;1.32;1.45;1.35;1.14;1.3;1.35;1.6;1.39;1.37;1.6;1.26;1.34;1.46;1.41;1.3;1.37];
figure(1)
plot(time_format,data,'c','LineWidth',1.75)
In the figure1, values of time_format cannot match the time_format array. How can I keep the exact value of time_format while plotting?
time format consists of day-hour-minute values. I cannot find day-hour-minute format in matlab. So in figure1, some values like 06:40:00 shouldn't be seen.

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by KL
on 7 Sep 2017
 Accepted Answer

Because you have a jump from 06:23:00 to 07:00:00. Add the following line to your code and set the xticks explicitly.
xticks([time_format(1) time_format(6) time_format(11) time_format(15) time_format(20) time_format(25)])

  4 Comments

Show 1 older comment
KL
on 7 Sep 2017
Which version of Matlab are you using?
set(gca,'xtick',[time_format(1) time_format(6) time_format(11) time_format(15) time_format(20) time_format(25)])
2015a
this time, I received; error using set While setting the 'XTick' property of Axes: Value must be a vector of type single or double whose values increase

Sign in to comment.