Plotting weekly graph of power values

4 次查看(过去 30 天)
Hi,
I am having per day data real-time for power values. I am averaging per hour hence getting 24 averaged values for 24 hours. Now i would like to plot weekly data. On x-axis labelled as date like (03-Mar-2018 to 09-Mar-2018) Total power value points will be (24*7 = 168.
How to plot 7 days on x axis with 168 power values.
This plot needs to show weekly data dividing per day averaged values.
Can anybody tell me detailed example of how this can be done.
Regards Vaishali

回答(1 个)

ag
ag 2025-3-12
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!

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by