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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!