필터 지우기
필터 지우기

scatterplot with the datetime

조회 수: 27 (최근 30일)
Ram Basnet
Ram Basnet 2021년 5월 25일
댓글: Star Strider 2021년 5월 27일
Hello everyone,
I am learning Matlab from very basic. I am quite clear what to do but, I am not sure how to procced. I have a dataset with 8 columns. The first one is datetime and other are power consumption. I want to scatter plot the given data according to hours throughout the year with the second column. As the datetime column has hourly based data I am not sure how to extract that data and scatterplot it.
Your help would be highly appericiated.

채택된 답변

Star Strider
Star Strider 2021년 5월 26일
One approach —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/630240/household_power_consumption_2007.zip')
Uz = 1×1 cell array
{'household_power_consumption_2007.csv'}
T1 = readtable(Uz{1})
T1 = 521669×8 table
DateTime Global_active_power Global_reactive_power Voltage Global_intensity Sub_metering_1 Sub_metering_2 Sub_metering_3 ____________________ ___________________ _____________________ _______ ________________ ______________ ______________ ______________ 01-Jan-2007 00:00:00 2.58 0.136 241.97 10.6 0 0 0 01-Jan-2007 00:01:00 2.552 0.1 241.75 10.4 0 0 0 01-Jan-2007 00:02:00 2.55 0.1 241.64 10.4 0 0 0 01-Jan-2007 00:03:00 2.55 0.1 241.71 10.4 0 0 0 01-Jan-2007 00:04:00 2.554 0.1 241.98 10.4 0 0 0 01-Jan-2007 00:05:00 2.55 0.1 241.83 10.4 0 0 0 01-Jan-2007 00:06:00 2.534 0.096 241.07 10.4 0 0 0 01-Jan-2007 00:07:00 2.484 0 241.29 10.2 0 0 0 01-Jan-2007 00:08:00 2.468 0 241.23 10.2 0 0 0 01-Jan-2007 00:09:00 2.486 0 242.18 10.2 0 0 0 01-Jan-2007 00:10:00 2.492 0 242.46 10.2 0 0 0 01-Jan-2007 00:11:00 2.5 0 242.88 10.2 0 0 0 01-Jan-2007 00:12:00 2.494 0 242.57 10.2 0 0 0 01-Jan-2007 00:13:00 2.492 0 242.41 10.2 0 0 0 01-Jan-2007 00:14:00 2.48 0 241.81 10.2 0 0 0 01-Jan-2007 00:15:00 2.478 0 241.73 10.2 0 0 0
figure
scatter(T1.DateTime, T1.Global_active_power, '.')
grid
MeanHourlyConsumption = groupsummary(T1, 'DateTime', 'hourofday', 'mean', 'Global_active_power')
MeanHourlyConsumption = 24×3 table
hourofday_DateTime GroupCount mean_Global_active_power __________________ __________ ________________________ 0 21741 0.74066 1 21720 0.5522 2 21719 0.46917 3 21720 0.42062 4 21720 0.41507 5 21720 0.42935 6 21720 0.80487 7 21720 1.4331 8 21699 1.502 9 21719 1.3085 10 21720 1.2181 11 21719 1.1809 12 21717 1.1473 13 21720 1.0948 14 21756 1.0827 15 21780 1.0167
figure
scatter(MeanHourlyConsumption{:,1}, MeanHourlyConsumption{:,3}, 's')
grid
.
  댓글 수: 6
Ram Basnet
Ram Basnet 2021년 5월 27일
Thankyou so much. Really appreciate your help.
Star Strider
Star Strider 2021년 5월 27일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by