Time plotting in MATLAB

1 次查看(过去 30 天)
Alexander Abadom
Alexander Abadom 2020-7-9
编辑: jonas 2020-7-9
i tried to plot the time variation on X-axis but it showning today's date (Please, how can i format the x-axis to show only the time and not both time and date on the x-axis)? i do not want todays date (Jul 9,2020 to be showing on the x-axis)
Also how can i increase the number of points on x-axis to vary every on hour or 2 hours instead of 6 hours?
See the screenshot of the excel sheet & plot attached
%% Read different data sets1
% Read data sets for current1, voltage1, radiation1,time1,tem1,temp2;
% Create figure
figurea = figure(1);
% Create axes
axes1 = axes(figurea);
hold(axes1,'on');
% Create plot
plot(time,radiation1,'LineStyle','--','Color',[1 0 0]);
% Create ylabel
ylabel('Radiation','FontWeight','bold','FontName','Arial');
% Create xlabel
xlabel('TimeOfDay','FontWeight','bold','FontName','Arial');
% Create title
title('Electrical performance1');
legend('SOlarIrradiation');
Str={'Solar Variation/Time Graph', 'of LSC Device'};
txt1=text(10,3000,Str,'Color','blue','Fontsize',16);
box(axes1,'on');
xtickformat('HH:mm:ss');

回答(1 个)

jonas
jonas 2020-7-9
编辑:jonas 2020-7-9
You can delete the secondary label (undocumented property),
delete(ax.XAxis.SecondaryLabel)
...but I would just plot the data as duration class instead, so that the time is not associated with a date.
Assuming your data is in datetime format:
t = timeofday(time)
plot(t,radiation1,'LineStyle','--','Color',[1 0 0]);
Changing the ticks, assuming your data is in duration format:
ax = gca;
ax.XTick = hours(0):hours(2):hours(24);

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by