MATLAB Fundamentals>>>Smoothing Electricity Data

MATLAB Fundamentals>Common Data Analysis Techniques>Smoothing Data> (3/5) Smoothing Electricity Data

数据准备:This code sets up the activity.

load electricityData
whos
total = usage(:,end);
sectorUsage = usage(:,1:3);
sectors = sectors(1:3);
plot(dates,total,".-")

说明1:

The table edata contains monthly electricity usage, in MWh, for the U.S., separated by sector. The matrix sectorUsage contains the consumption for three sectors (residential, commercial, and industrial). The vector total contains the total consumption. The months are stored in the datetime vector dates.

You can smooth the data using the smooth data function.

dataSm = smoothdata(data,"movmean",n)


When the data are evenly sampled, you do not need to specify the sample points.

任务1:

Calculate the 1-year moving average of total. Add this to the existing plot using point markers and a solid line. Repeat for the 2-year moving average.

解答1:

total12 = smoothdata(total,"movmean",12)
hold on 
plot(dates,total12,".-")
total24 = smoothdata(total,"movmean",24)
plot(dates,total24,".-")
hold off

结果1:


说明2:

The smoothdata function works column-wise on matrices. The sectorUsage variable contains usage data from three sectors in its three columns.

任务2:

Calculate the 2-year moving average of all the sectors in sectorUsage. Create a new plot of the result against dates. Use solid lines and no markers.

解答2:

sectorUsage24 = smoothdata(sectorUsage,"movmean",24)
plot(dates,sectorUsage24,"-")

结果2:


附加练习:

The dates are spaced one calendar month apart. However, the months have different lengths, so the usage data is spaced slightly unevenly. To use the dates as sample points, you need to specify the window length as a duration.
 

nDur = years(2)
useSp = smoothdata(sectorUsage,"movmean",...
    nDur,"SamplePoints",dates)
plot(dates,useSp)


The data look almost identical, but a closer look at the difference reveals that they are not.

stem(dates,sectorUsage24-useSp)
legend(sectors)


Here, sectorUsage24 represents the 2-year moving average of all the sectors in sectorUsage, but you may have given this variable from the last task a different name.

附加代码:

nDur = years(2)
useSp = smoothdata(sectorUsage,"movmean",nDur,"SamplePoints",dates)
plot(dates,useSp)

stem(dates,sectorUsage24-useSp)
legend(sectors)

附加结果:


笔记:附加部分的练习到底有何不同,”SamplePoints“到底该怎么用?

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-01-26 20:02:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-26 20:02:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-26 20:02:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-26 20:02:04       20 阅读

热门阅读

  1. 代码随想录算法训练营29期Day30|LeetCode 332,51,37

    2024-01-26 20:02:04       38 阅读
  2. linux shell脚本 条件语句

    2024-01-26 20:02:04       31 阅读
  3. Spring之基于注解的IOC(DI)

    2024-01-26 20:02:04       30 阅读
  4. 第七章SQL编程(持续更新中)

    2024-01-26 20:02:04       25 阅读
  5. 如何利用 chatgpt 提高查询效率

    2024-01-26 20:02:04       31 阅读
  6. 倒计时80天

    2024-01-26 20:02:04       33 阅读
  7. DNS故障的几种常见原因及解决方法

    2024-01-26 20:02:04       35 阅读