필터 지우기
필터 지우기

How to interact with Figure while input() is active

조회 수: 32 (최근 30일)
Asad Ali
Asad Ali 2016년 8월 29일
답변: Zhiyu Zhang 2020년 12월 21일
The goal is to capture the index of the data point the user is interested in.
For example, let's say a figure has 100 points randomly across it:
plot(randn(1000,1))
Each of the 100 points has further details associated with it, and I ask the user which data point he wants to investigate:
idx = input("please select data index to see its details")
The issue is that as soon as the input() command is issued, the user cannot interact with the figure. Can't zoom in, can't select data cursors etc, so it's difficult for the user to know that he is putting in the right index.
I don't think I had this problem with r2013b where issuing user() did not make the figure non-interactive. Is there something easy I'm missing here?

답변 (4개)

ThiBi
ThiBi 2020년 3월 26일
Has this been solved by now? I am encountering the same issue in MATLAB R2019a.
  댓글 수: 1
ThiBi
ThiBi 2020년 3월 26일
Just found out that this command exists:
[x,y] = ginput
Sorry for digging up this old thread, but maybe this is helpful for someone.

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


Walter Roberson
Walter Roberson 2016년 8월 29일
R2016a changed how input() worked, and it is not currently possible to interact with the figures while you are inside an input(). Some people have remarked on this, so it would not surprise me if this was one of the things changed in R2016b (but I do not know.)
  댓글 수: 2
Asad Ali
Asad Ali 2016년 8월 29일
That is unfortunate.
Is there at least some command which lets the user interact with figures until a certain button is pressed?
Walter Roberson
Walter Roberson 2016년 8월 30일
You can use waitfor() to wait for a graphics object to be destroyed or for a graphics object property to become a certain value. User mbonus mentions uiwait() in their answer: uiwait() is a convenient but more limited interface to waitfor()

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


mbonus
mbonus 2016년 8월 29일
You can try to create a GUI and use uiwait(hObject). Then you can just have program execution resume when the user clicks on the data point and use the pixel coordinates of the mouse pointer so that they don't have to enter any information.

Zhiyu Zhang
Zhiyu Zhang 2020년 12월 21일
You just need to use the pause function before your input function. For example:
pause(5);
input(...);
This will allow you to manipulate the plot even pause is over.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by