Displaying MATLAB Plot X-Axis in Hours (from Seconds)
When MATLAB plot X-axis values are in seconds and you want them displayed as hours, there are two common approaches:
1. Convert seconds to hours directly
If your time vector is stored in seconds, divide the vector by 3600 before plotting:
t = out.simlog.time; % time in seconds
t_hours = t/3600;
plot(t_hours, data)
xlabel('Time (hours)')
Example: 7200 seconds = 2 hours.
2. Keep time in seconds but display the X-axis as hours
If you prefer not to modify your underlying data array, re-label the axis tick marks:
plot(t, data)
xt = xticks;
xticklabels(string(xt/3600))
xlabel('Time (hours)')
Plotting Simulink Results
For your typical out.simlog data structure:
t = out.simlog.time;
data = out.simlog.signals.values;
t_hours = t/3600;
plot(t_hours, data)
xlabel('Time (hours)')
ylabel('Value')
grid on