How can I get a different values from a gui button, depending on if it's up or down?

3 views (last 30 days)
Hello,
I'm new to matlab.
I'm creating a gui where I want a different value in a specific variable (say, buttonValue), depending on if the user is currently holding down a button or if they are not holding down that button.
I want to be able to do two things with this information.
1. run code only while it is pushed down (using an if statement, presumably)
2. be able to access the value of buttonValue in other parts of my code (using get(), presumably)
From what I've looked up, push buttons only cause a section of code to run; they can't store a value of up or down. Toggle buttons have to be pushed twice for their value to change. Neither of these seems to work for what I'm looking for.
Thank you, in advance, for your help.
edit: To be more clear:
While the left mouse button is held down over this button, buttonValue should equal 1.
While the left mouse button is not held down over this button, buttonValue should equal 0.
  2 Comments
Jan
Jan on 9 Mar 2015
Toggle button do not have to be pushed twice to change their value. Thjere I do not understand, what you exactly want. What do you mean by "push"? Clicking with the mouse while the mouse is still down? Or is it enough if the event is triggered, when the mouse button is released?
Matlab_Learner
Matlab_Learner on 9 Mar 2015
Thank you for your response. To be more clear:
While the left mouse button is held down over this button, buttonValue should equal 1.
While the left mouse button is not held down over this button, buttonValue should equal 0.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!