MATLAB Answers


how can I select a part of data with dual cousors and get the average in a curve?

Asked by haojun
on 12 Jan 2013

I want to select a part of curve in a figure with mouse interactively, and get the average value of this part of data automatically. For example,I select a part of data with dual cursors or two vertical lines with mouse in a curve, the matlab give the average value between them, how can I do it? thanks you.


on 12 Jan 2013

What do you mean? Clicking on the figure to select a data range?

Walter Roberson
on 12 Jan 2013

What values should the average be taken of?


No products are associated with this question.

1 Answer

Answer by Teja Muppirala
on 16 Jan 2013

I think the simplest way to do this would be to use the brush feature.

1. Plot your data

2. From the figure toolbar, select the brush (next to the data cursor button)

3. Draw a box around the data

4. Right-click on the brushed data and create a new variable in the workspace

5. Take the mean of the data from the workspace.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!