Finding the mean along X axis on plot?

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 3 Jul 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 Comments
Hugo
Hugo on 3 Jul 2015
Edited: Hugo on 3 Jul 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
Walter Roberson on 3 Jul 2015
Alt = vertcat(data2.altitude);
should do fine with column vectors.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!