Hi Vaishali,
To plot weekly data with hourly averaged power values in MATLAB, you can follow the below steps.
- Ensure you have a vector of 168 power values representing hourly averages for 7 days.
- Generate a date vector that corresponds to each hour over the 7-day period.
- Plot the data
The below code snippet demonstrates how to plot a graph where the x-axis is labeled by date, showing the hourly averages for each day over a week:
% random data
powerValues = rand(1, 168) * 100;
startDate = datetime('03-Mar-2018', 'InputFormat', 'dd-MMM-yyyy');
% Create a datetime vector for each hour over the 7 days
dateVector = startDate + hours(0:167);
% Plot the data
figure;
plot(dateVector, powerValues, '-o');
xlabel('Date');
ylabel('Average Power (units)');
title('Weekly Power Data (Hourly Averages)');
% Format the x-axis
ax = gca;
ax.XTick = startDate + days(0:6); % Set ticks at the start of each day
ax.XTickLabelRotation = 45; % Rotate labels for better readability
ax.XAxis.TickLabelFormat = 'dd-MMM-yyyy'; % Format the date labels
For more details, please refer to the following MathWorks documentations:
- datetime - https://www.mathworks.com/help/matlab/ref/datetime.html
- plot - https://www.mathworks.com/help/matlab/ref/plot.html
- gca - https://www.mathworks.com/help/matlab/ref/gca.html
Hope this helps!

