Show the mean and standard Deviation values of each cell array member
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello!
I want to get the mean delay, standard deviation, max delay and min delay of each airport but the code that I made up is only returning the results for airport DFW.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/863545/image.png)
Is there something wrong with my code?
F = dataset('xlsfile','Delta_Data');
% Airport Departure Statistics
Origin = {'CVG','ATL','ORD','LAX','MIA','DFW'};
for k = 1:6
Origin_Flights = find(strcmp(F.Origin,Origin(k)));
Number_Flights = length(Origin_Flights);
Mean_Delay = mean(F.Delay(Origin_Flights));
ST_Dev = std(F.Delay(Origin_Flights));
Max_Delay = max(F.Delay(Origin_Flights));
Min_Delay = min(F.Delay(Origin_Flights));
end
disp(Mean_Delay);
disp(ST_Dev);
disp(Max_Delay);
disp(Min_Delay);
Here is what I get when I run the code:
9.4474
42.5381
297
-10
How can I code it in such a way that it will show the results of each airport? I hope you could help me with this.
Thank you so much!
댓글 수: 0
채택된 답변
Tina
2022년 1월 15일
Hi there!
You did made a for loop but you are not using k anywhere in code except for origin flights.
If we assume that your data is in such way that first colunm has data of first airport and so on
then try this
for k = 1:6
Origin_Flights = find(strcmp(F.Origin,Origin(k)));
Number_Flights = length(Origin_Flights(k));
Mean_Delay = mean(F.Delay(Origin_Flights(k)));
ST_Dev = std(F.Delay(Origin_Flights(k)));
Max_Delay = max(F.Delay(Origin_Flights(k)));
Min_Delay = min(F.Delay(Origin_Flights(k)));
end
or by this
for k = 1:6
Origin_Flights = find(strcmp(F.Origin,Origin(:,k)));
Number_Flights = length(Origin_Flights(:,k));
Mean_Delay = mean(F.Delay(Origin_Flights(:,k)));
ST_Dev = std(F.Delay(Origin_Flights(:,k)));
Max_Delay = max(F.Delay(Origin_Flights(:,k)));
Min_Delay = min(F.Delay(Origin_Flights(:,k)));
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!