Increasing ticks on x-axis when using datenums?
조회 수: 8 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Cris LaPierre
2020년 7월 28일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!