How to make changes in the table

조회 수: 1 (최근 30일)
Behrooz Daneshian
Behrooz Daneshian 2023년 1월 10일
댓글: the cyclist 2023년 1월 11일
Hi all,
I have a table reporting daily minimum tempreature(TMIN) and maximum tempretaure (TMAX) for year of 2017. How can I make changes to this table so that I can have daily average tempreature for each date. The table is attached for your further investigations.
  댓글 수: 2
Matt J
Matt J 2023년 1월 11일
You mena you have additional data that you want to insert? If not, where are the average values supposed to come from?
Behrooz Daneshian
Behrooz Daneshian 2023년 1월 11일
편집: Behrooz Daneshian 2023년 1월 11일
No i just want to calculate TAVG=(TMIN+TMAX)/2 and substitue it to TMIN and TMAX. In other words, I want to have one TAVG corresponding to a day.

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

채택된 답변

the cyclist
the cyclist 2023년 1월 11일
Probably the easiest way to do this is via the following data operations:
  • "unstack" the max/min temperatures into their own columns
  • Take the average
  • "stack" the temperatures again (if you want)
Here is the code:
load("newyearTemp.mat","newyearTemperatureData")
unstackedTemperatureData = unstack(newyearTemperatureData,"value","datatype");
unstackedTemperatureData.TAVE = (unstackedTemperatureData.TMAX+unstackedTemperatureData.TMIN)/2;
restackedTemperatureData = stack(unstackedTemperatureData,["TMAX","TMIN","TAVE"],'NewDataVariableName','value','IndexVariableName','datatype');
I also feel obligated to mention that the daily average temperature is not typically the mean of the high and low. But guessing you know that. :-)
  댓글 수: 1
the cyclist
the cyclist 2023년 1월 11일
Possibly helpful for you in the future is also to become familiar with what is known as the "tidy" data format, where the features (e.g. "station" or "max temperature") are the column, and the observations (e.g. "GHCND:USC00017674" and "68") are the rows.
The unstacking I did put your data into that format, which made it much easier to do the averaging operation on all the observations at once.
I suppose that one could argue that "datatype" is a feature, and "TMAX" is an observation. Sometimes it is tricky. But I like to spread the gospel of tidy data.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by