필터 지우기
필터 지우기

help using grpstat() function

조회 수: 5 (최근 30일)
Andrew
Andrew 2014년 9월 28일
답변: Sreeja Banerjee 2014년 9월 30일
load carbig
- Use the grpstats() function to find the mean, maximum and minimum MPG for cars manufactured in each year.
- Use an appropriate visualisation method to display the MPG data for each year. Does this data show a
trend? (i.e is MPG tending to increase/decrease over time?)
Q: returning errors when i process grpstats(x,MPG,'mean'), need some help please
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2014년 9월 28일
Andrew - what errors are you observing? Please include the complete error message and any (code) line number that it corresponds to.

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

채택된 답변

Sreeja Banerjee
Sreeja Banerjee 2014년 9월 30일
I understand that you are facing issues while trying to use the function "grpstats". The syntax for using the "grpstats" function is:
statarray = grpstats(tbl,groupvar,whichstats)
This syntax finds summary statistics specified in "whichstats" based on grouping variable "groupvar" for the data specified in "tbl". Thus, to find the mean, maximum and minimum MPG for cars manufactured in each year in the "carbig" dataset you have to use the following commands:
%%Statistics
meanMPG = grpstats(MPG,Model_Year,'mean');
maxMPG = grpstats(MPG,Model_Year,'max');
minMPG = grpstats(MPG,Model_Year,'min');
One way to visualize the MPG statistics by year is to use "errorbar". This function has the following syntax:
errorbar(X,Y,E)
Thus, for the dataset mentioned in this question, "Y" is the mean MPG which is plotted with respect to "X" or the Model_Year. The advantage of using this function is that the error "E" can be replaced with the standard deviation which is then plotted as an error bar. here is some code to do the same:
%%Code to visualize MPG statistics over time
stdMPG = grpstats(MPG,Model_Year,'std'); % Find standard deviation
errorbar(unique(Model_Year),meanMPG,stdMPG);
xlabel('Model year');
ylabel('MPG');
title('MPG over Time');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by