Time plotting in MATLAB

6 views (last 30 days)
Alexander Abadom
Alexander Abadom on 9 Jul 2020
Edited: jonas on 9 Jul 2020
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);
% Create plot
plot(time,radiation1,'LineStyle','--','Color',[1 0 0]);
% Create ylabel
% Create xlabel
% Create title
title('Electrical performance1');
Str={'Solar Variation/Time Graph', 'of LSC Device'};

Answers (1)

jonas on 9 Jul 2020
Edited: jonas on 9 Jul 2020
You can delete the secondary label (undocumented property),
...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);


Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!