Question

I created a diagram presenting limb movement over the time (2.56 seconds). My diagram looks like in the top Picture 1. enter image description here

My code to get the diagram was:

x=data(1000:1256,2)
Fs=100      
Ts=1/Fs         
L=length(x)  
t = (0:L-1)*Ts;  
figure      
plot(t,x);

Now Im trying to change time units into real time data (day and time, when the measurements were recorded), I want to get something like in the Picture 2: mark x-axis with date and time. Ideally Id like to have 6 time marks.

Using:

datestr(data(1000),'dd-mm-yyyy HH:MM:SS AM')

I know the first time (row 1000th of my data) is 10-07-2010 11:31:50 PM and the last row (1256th) is 10-07-2010 11:43:42 PM. There was always 50 records recorded per 1 second, BUT the problem is, the measurements were not recorded constantly - I mean, sometimes there was no measurements for a few minutes (when there was no movement).

I ve been trying to use XTick etc but I dont know how to select the real-time data for my x-axis and how to label x-axis with the real time of measurements.

labels=datestr(data);
set(gca,'XTick',1:6; 'XTickLabel',labels);

Anybody could help me?

Was it helpful?

Solution

This should format the tickmarks

datetick('x', 'dd-mm-yyyy HH:MM:SS AM')

It might go after setting the tickmarks

set(gca,'XTick',[ ... ])

Where in the array you should put the datenum values of your times.

Consider this minimal example:

x = linspace(now-2, now, 30);
y = rand(30, 1);
plot(x, y)
datetick('x', 'dd-mmm HH:MM')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top