Question: MATLAB: I need help setting up a GUI in Matlab for a Create a script that shows an image, with 4 buttons. The buttons should
MATLAB: I need help setting up a GUI in Matlab for a
Create a script that shows an image, with 4 buttons. The buttons should say "up", "down", "left", and "right". Place the buttons in user-friendly locations, i.e. the "left" button should be somewhere to the left of the "right" button. Use the uicontrol function for these, and refine the positions until they are where you want them. (For this assignment, do not use the GUIDE tool. GUIDE is a good thing to know, but doing this assignment without that will give you a good understanding of what it does. You could use the ginput command to help figure out where you want things.)
Using a 256x256 image as foundation, your program should behave in the following way.
- Only show 128x128 of the image at any time.
- The four buttons should change what part of the image is shown, in increments of 64.
- E.g. suppose that the image is showing the upper-left corner when the user presses the "down" button. Instead of showing 1:128, 1:128, it should respond by showing 64+1:64+128, 1:128.
- Then, if the user presses "right", it should respond by showing 64+1:64+128, 64+1:64+128.
- If the user presses a button to move the image in a direction, but it cannot move more in that direction, display an appropriate message and ignore the button press. (This should not be an error message, just an informational one.) For example, if it is showing 1:128, 1:128, it cannot go either up or left, so those should be ignored outside of printing the message.
- You will need to make a callback function that responds to the buttons. Rather than create a separate callback function for each button, you can have one that handles all four. An easy way to do this is to pass a unique number to the callback from each button, i.e. the "up" button could have a code of 1, "down" a code of 2, etc.
- When a button is pressed, "disp" a message to the command window telling the user what the callback function is doing, such as "moving up".
- The callback function will need to access some variables. Make the image variable global, along with the current starting row and current starting column. The amount to show (128) and the amount to move (64) could also be stored in global variables.
Putting all of this together, you should have a script that shows a GUI with 4 buttons and a image, where the image part is a 64x64 square of a larger image. You will also have a callback function that responds to the button presses. The buttons allow the user to move the square around to see other parts of the image.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
