Plotting minutes relative to minutes as formatted time (min.sec)

I am trying to build some data regarding minutes instead of seconds in Matlab as a formatted time, i.e. min.sec .

I have real-time streaming data, where time in seconds is also sent with each sample received. Then I draw them in relation to time. Now, since my session lasts about 15 minutes, I can’t think about the time. So I wanted to build it in time ( min.sec ). I tried to divide the resulting time by 60, but this gives me minutes with 100 divisions instead of 60 (increment of minutes after 0.9999 instead of 0.59). How to convert it so that I can plot the time in minutes?

This is what I mean by 0.99 fractions of a minute instead of 0.59. A normal minute has 60 divisions not 100. enter image description here

EDIT: I tried the m7913d sentences, and here is what I got.

  • first I draw a signal relative to time in seconds without changing ticks (A normal plot(t,v) )

  • I added datetick('x', 'mm:ss'); to plot (Xtick format is not supported in Matlab 2015b)

Here is a screenshot of the results enter image description here

The time in seconds was up to 80 seconds, when it is converted to minutes, it should give me 1 minute and 20 seconds as the maximum limit of the x axis. But this is not so. I tried to build a t-vector (for example, t=0:seconds(3):minutes(3) ), but I could not associate it with a vector of seconds, which will be constantly updated as new samples arrive from the serial port. Thanks

+5
source share
1 answer

You can use xtickformat to specify the desired format for your x-tags as follows:

 % generate a random signal (in seconds) t = 0:5:15*60; y = rand(size(t)); plot(seconds(t),y) % plot your signal, making it explicit that the t is expressed in seconds xtickformat('mm:ss') % specify the desired format of the x labels 

Note that I used the seconds methods, which returns duration to tell Matlab that t is expressed in seconds.

Exit the above script (the right image is an enlarged version of the left image):

enter image description here enter image description here

Pre r2016b

You can use datetime instead of xtickformat as follows:

 datetimes = datetime(0,0,0,0,0,t); % convert seconds to datetime plot(datetimes,y) datetick('x', 'MM:SS'); % set the x tick format (Note that you should now use capital M and S in the format string xlim([min(datetimes) max(datetimes)]) 
+1
source

Source: https://habr.com/ru/post/1268944/


All Articles