Increasing ticks on x-axis when using datenums?

3 visualizzazioni (ultimi 30 giorni)
Hi all, question is exactly as the title says. First time working with datenums so I'm kind of flying by the seat of my pants on this. I'll include the entirety of my code since it's short enough.
% Read from .csv file
data = readtable('filename.csv', 'HeaderLines',2);
%%
% parsing the table
time = data(:,1);
real = data(:,2);
reactive = data(:,3);
% serializing time and converting tables to arrays
time = table2array(time); % Format: yyyy-mm-dd HH:mm:ss
real = table2array(real); % [
reactive = table2array(reactive);
datenumber = datenum(time);
type = class(datenumber)
plot(datenumber,real)
datetick('x', 'yyyy-mm-dd')
xlabel('\sl\bfDate')
ylabel('\sl\bfReal Power [kW]')
title('\sl\bfReal Power vs. Time')
% XTicks = [datenum(2015,1,1):datenum(2020,1,1)]
% XTickLabels = datestr(XTicks,6);
% set(gca,'XTick',XTicks,'XTickLabel',XTickLabels)
You can see that the last three lines are me experimenting with how to increase the x-ticks, but it's if I utilize those lines, a solid black box appears where I would typically have values on the x-axis.
Here is the output:
Ultimately, I aim to have ticks at each half year mark between 2015 and 2020.
Any help would be appreciated!

Risposta accettata

Cris LaPierre
Cris LaPierre il 28 Lug 2020
This is handled automatically for you if you use datetimes. Use the function dateime to convert your time to a datetime. Then plot that as x instead of datenum. Format the appearance using xtickformat.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by