Finding the mean along X axis on plot?

1 Ansicht (letzte 30 Tage)
bio lim
bio lim am 3 Jul. 2015
Kommentiert: Walter Roberson am 3 Jul. 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by