Show the mean and standard Deviation values of each cell array member
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!