Getting average from Matlab plot?

I have a simple plot that contains many data points when I have a graph. Is there a way that I can just click on all of these points and let Matlab give me their average value?

thank

+3
source share
4 answers

The easiest way, if you do not want to do this programmatically, is to use a data brush and statistics.

I used plot(rand(1,200))to generate my data. After that, go to Tools> Data Statistics. Y-mean is what you are looking for.

alt text http://www.thinkextensively.com/misc/stackoverflow/images/matlab2.png

, , "" > "" > " ".,.. , . mean(ans). - Y. alt text http://www.thinkextensively.com/misc/stackoverflow/images/matlab1.png

+1

.

. Tools-Brushing-Create . ans. X Y . mean(ans(:,2)), Ys.

+2

, . , y-.

RBBOX .

:

% sample data
data = rand(1,100);
datax = 1:numel(data);

% draw simple plot
plot(data,'.')

% select the points with mouse and get coordinates
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint');    % button down detected
finalRect = rbbox;                   % return figure units
point2 = get(gca,'CurrentPoint');    % button up detected
point1 = point1(1,1:2);              % extract x and y
point2 = point2(1,1:2);
pmin = min(point1,point2);
pmax = max(point1,point2);

% find the data selected and get average of y values
idx = data >= pmin(2) & data <= pmax(2) & datax >=pmin(1) & datax <= pmax(1);
dataAverage = mean(data(idx));

rbbox.

0

, (, , ) .

plotAverage Matlab, .

%# plot some data
figure
plot(randn(100,5))

%# add the average line at every 5th point
[plotHandles, average] = plotAverage([],5:5:95);

%# and you have a line on the plot, and its handles and data in the workspace.
0

Source: https://habr.com/ru/post/1739393/


All Articles