1
votes

I'm trying to find a solution to plot a data series vs a date time variable set.

The initial format of the date time variable set was "01/01/2015 01:10:00", so I converted them to a better format to work with using datenum, like the following:

% Original Date Time Variable - Data.datetime.str(j,1:19)

Auxiliar.formatIn = 'dd/mm/yyyy HH:MM:SS';
for j = 1:length(Data.time)
   Data.datetime.num(j,1) = datenum(Data.datetime.str(j,1:19), Auxiliar.formatIn);
end

After that, it was possible to plot everything using:

% Original Data Series - Data.anem1.max

plot(Data.datetime.num, Data.anem1.max)
labels = datestr(Data.datetime.num, 6);
set(gca, 'XTick', Data.datetime.num);
set(gca, 'XTickLabel', labels);

But the result is the one shown here: .

The high density of labels on the x axis does not benefit me, since it's impossible to see anything and some points of the data series share the same day, for example.

How should I proceed to show the same day just once, limitting the the plot to a certain amount of labels?

1

1 Answers

0
votes

You can use the fact that MATLAB datenums are in units of days to generate your labels:

days = [floor(min(Data.datetime.num)):ceil(max(Data.datetime.num))]

labels = datestr(days, Auxiliar.formatIn)

plot(Data.datetime.num, Data.anem1.max)
set(gca, 'XTick', days);
set(gca, 'XTickLabel', labels);

days will be an array of integers representing the days from midnight before the start of your data to the midnight after the end. If you want noon instead of midnight, you can do days = days + 0.5. You may also want to replace datestr(days(i), Auxiliar.formatIn) with something that suits you in terms of output format.