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);

Community Treasure Hunt

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

Start Hunting!

Translated by