GUI Newbie

1 visualizzazione (ultimi 30 giorni)
Steve
Steve il 31 Gen 2012
I'm still a newbie when it comes to programming buttons in MatLab. I need to be able to add a button to a figure that acts as a start/stop button. I was able to get the button to appear on the figure, but I'm not sure how to handle the callback. Can someone help send me in the right direction?
Here is the code I have to format the button:
uicontrol('Style', 'pushbutton', 'String', ' Start/Stop ',...
'Position', [15 15 100 50],'FontSize',10,'FontWeight',...
'bold','Callback', 'cla');
Overall this is what I want to accomplish:
while(The button is depressed)
execute code
end
Thank you!

Risposta accettata

Walter Roberson
Walter Roberson il 1 Feb 2012
Assign the output of uicontrol() to a handle. Save the handle somewhere. Then in the routine that needs to check the state of the button, get() the 'Value' property of the button: 0 will indicate it is not pressed and 1 will indicate that it is pressed.
  1 Commento
Assad
Assad il 7 Feb 2012
i want to make my Push Button work on keyboard keys how can i do it

Accedi per commentare.

Più risposte (4)

Jeff
Jeff il 1 Feb 2012
Steve,
Here are my suggestions considering that you are new to at least MatLab and perhaps programming in general (you didn't say so forgive me if I'm wrong).
1. Use GUIDE to to design the interface including the formatting of the button. Just let GUIDE do it for you without worrying about needing to learn the additional code.
2. If you right click on the button in GUIDE you will be presented with a menu. There will be a selection called View Callbacks. That leads to a list, the first of which is Callback. Click that and you will be taken to the code editor and more importantly to the callback for that control. This is where you enter the actual code you want to execute after the button is clicked.
3. Read and re-read the copious Product Help and User Guides. They are great. This is one area where MatLab really shines. Use it.

Image Analyst
Image Analyst il 31 Gen 2012
I think MAGIC might be a good place to start. http://www.mathworks.com/matlabcentral/fileexchange/24224 It has all the controls and some simple stub controls that do things when you click on them, like say "you clicked on this" or display an image, or display the value of a scroll bar. You can then fill in the guts of the callback with your own code to do what you want. Here's a description:
This GUI will help the novice user get up to speed very quickly on using GUI-based applications. Everything is laid out in a very simple Step 1, Step 2, Step 3, etc. layout. It is a very good starting point for a typical image analysis application. This application uses GUIDE to do the user interface design, and has most of the basic controls such as buttons, listboxes, checkboxes, radio buttons, scrollbars, etc. It allows the user to select a folder of images, select one or more images and display them, to select a series of options, and to individually or batch process one or more images. The user can optionally apply a mask (region of interest) to the image so that only the area within the mask will be analyzed. The results are optionally sent to Excel. In this demo, I do some very basic particle sizing but in use, the user would replace that simple demo code in the function AnalyzeSingleImage() with their own code. Works with Windows or Unix since paths are all forward slashes. Requires the Image Processing Toolbox to do the simple particle sizing demo, but if you delete that demo code before using it, then the IP toolbox would not be required and it would still demonstrate the basic GUI-based file processing functionality.

Steve
Steve il 31 Gen 2012
Thanks for the help, but this doesn't exactly relate to what I'm doing. I basically need to check the state of the pushbutton within my code.

Steve
Steve il 2 Feb 2012
Thanks Jeff and Walter! This forum is awesome. I am so used to car forums where nobody gives positive feedback.

Categorie

Scopri di più su Migrate GUIDE Apps 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