Finding the mean along X axis on plot?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
bio lim
le 3 Juil 2015
Commenté : Walter Roberson
le 3 Juil 2015
Hello. I am trying to find the mean along the X axis as follows.

As shown in the plot, I would like to find the mean of the 'GS-TAS' scatter plots on different altitudes. For example, by drawing a line perpendicular to the Altitude axis on 2.35x10^4 feet, you can see corresponding GS-TAS values. I would like to find the mean of those values, on all altitude levels then plot it against the altitude. Is it possible? Any simple methods to do it? Thanks.
0 commentaires
Réponse acceptée
Walter Roberson
le 3 Juil 2015
level_spacing = 500;
Alt = .... %vector of the altitudes of each data point
GSTAS = ... %vector of the GS-TAS for each data point
altbins = 1 + floor(Alt(:) ./ level_spacing); %convert altitude to relative level number
mean_gstas = accumarray(altbins, GSTAS(:), [], @mean, NaN); %all the real work
altlevels = level_spacing * (0:length(mean_gstas)-1);
plot(altlevels, mean_gstas, '*-');
With this code, any altitude level for which there is no data will not show a connecting line; no interpolation is implied. If you want connecting lines then change the plot() to
hasdata = ~isnan(mean_gstas);
plot(altlevels(hasdata), mean_gstas(hasdata), '*-');
3 commentaires
Hugo
le 3 Juil 2015
Modifié(e) : Hugo
le 3 Juil 2015
Hi coffee You can get the vectors that the answer of Walter require as follows. For example, in the case of the altitude, do this:
Alt = cell2mat(arrayfun(@(x)data2(x).altitude',1:numel(data2),'UniformOutput',false));
This certainly looks overly complicated for a reason: The data in your fields are column vectors. Should they be row vectors, you could have obtained the same by doing this:
Alt = [data2.altitude];
Hope this helps. Hugo
Walter Roberson
le 3 Juil 2015
Alt = vertcat(data2.altitude);
should do fine with column vectors.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!