Show the mean and standard Deviation values of each cell array member

2 vues (au cours des 30 derniers jours)
Erika
Erika le 15 Jan 2022
Commenté : Erika le 16 Jan 2022
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.
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!

Réponse acceptée

Tina
Tina le 15 Jan 2022
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
  1 commentaire
Erika
Erika le 16 Jan 2022
Hello, Tina!
Thank you so much for taking your time to answer my question, it really means a lot.
After much realization, it turns out that my code is correct all along. I figured that the display part of the code should've been inside the loop and not outside.
Again, thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by