How do I extract points from a plot for further computation?

조회 수: 4 (최근 30일)
I have this set of points: (time, voltage). I plotted the data and now I need to pick 2 time points between which I need to make an average of voltage values. I tried using this:
[x,y] = ginput(2)
But it is not getting me time in the x vector. Any suggestion? Thank you for your time and help!
  댓글 수: 2
Matthew Eicholtz
Matthew Eicholtz 2017년 10월 12일
What is it giving you in the x vector? I just tried it and got what I expected from ginput.
Andreia dos Santos
Andreia dos Santos 2017년 10월 12일
I just got this, for example: [0.750900921658986;1.385002304147465]. I could select anything, even if it was out of the plotted curve...

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

채택된 답변

Matthew Eicholtz
Matthew Eicholtz 2017년 10월 12일
Try using the Brush/Select Data tool. Here's an example...
Generate and plot some random data:
t = 1:1000;
x = randn(size(t))+sin(0.05*t);
plot(t,x);
Now click on the Brush/Select Data tool in the figure:
Draw a rectangle around the data of interest by click-and-drag:
Right-click on the selected data and choose "Create Variable" in the popup menu:
Follow the prompt to name the variable that stores the selected data, and you're good to go. The output in this example would be an Nx2 array in which the first column contains the x-axis data (time) and the second column contains the y-axis data (called x here).
Hope this helps.
  댓글 수: 1
Andreia dos Santos
Andreia dos Santos 2017년 10월 12일
Thank you! I actually needed the variables created by the brush to be further used on a script, but I found a way to make that happen. I named my plot as "f" and after plotting my data, I wrote:
waitfor(f);
Then I used the brush and named the variable created. I closed the plot figure, and the script continued working with the variable created.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by