How to pause code till specific key is pressed?

2 visualizzazioni (ultimi 30 giorni)
Mark Golberg
Mark Golberg il 10 Ott 2019
Commentato: Mark Golberg il 10 Ott 2019
Hello,
I want to do the following automatically:
  1. open figure
  2. select 2 datapoints with my mouse.
  3. read the index of those 2 datapoints, using the below code
dcm_obj = datacursormode(gcf);
info_struct = getCursorInfo(dcm_obj);
4. close figure
5. continue with the rest of the code.
Problem is, I don't know how to pause the script for it to wait till I finish selecting my datapoints.
I don't mind pressing a specific key after finish selecting the 2 datapoints.
THANK YOU!

Risposte (1)

thoughtGarden
thoughtGarden il 10 Ott 2019
Modificato: thoughtGarden il 10 Ott 2019
Seems like you could do this more easily like this:
[x,y] = ginput(2);
This allows you to get the data for two locations before it continues with your script. No need to press a specific key after.
  1 Commento
Mark Golberg
Mark Golberg il 10 Ott 2019
ginput gives you a general coordinates of where you pressed within the figure.
I'm interested in taking 2 data points from a given graph.
Imaging I have a very long plot. Now I want to manually select to data point (with data tip), so after my second selection the script would continue auomatically (or it's ok for me to press some key, for example the letter 'm', or SPACE, or something, and the it will allow to script to continue).

Accedi per commentare.

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by