Finding the mean along X axis on plot?

조회 수: 4 (최근 30일)
bio lim
bio lim 2015년 7월 3일
댓글: Walter Roberson 2015년 7월 3일
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.

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 3일
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
Hugo
Hugo 2015년 7월 3일
편집: Hugo 2015년 7월 3일
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 2015년 7월 3일
Alt = vertcat(data2.altitude);
should do fine with column vectors.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by