I am developing a GUI in MATLAB and am trying to allow a user to click on an image in order to enable a push button, and then this image will change like a toggle button, but I am struggling and am hoping for some advice, how can this be done?
I've seen that you can put icons on push buttons in MATLAB and that you can extract the position of the mouse on a click, but I can't figure out if these help my situation. I don't want to put the icon on the button because a) its not the look I am going for and b) I want to be able to change the image depending on the state of the button.
Thanks
The key to your problem is ButtonDownFcn. You need to set your images ButtonDownFcn to reference come function which both changes the image displayed, and does whatever else you need it to do. So, for example, say your create you image in you operating function like so:
...
yourImHandle = image(someImage);
set(yourImHandle, 'ButtonDownFcn', {#yourPushbuttonFcn, yourImHandle, otherVar});
...
Where yourPushbuttonFcn is defined elsewhere as:
function yourPushbuttonFcn(yourImageHandle, otherVar)
set(yourImageHandle, 'CData', someOtherImage);
otherVar=otherVar+1; %# Do other things.
end
This will change the image for you, and sets up the platform for you to do other, more complicated things inside the push button function. Let me know if you have any questions.
Good Luck.
Related
I would like to call a function and still run the default when the user clicks the chart legend as seen in the gif below.
The problem is that I couldn't find a way to just to INTERCEPT and not modify the way the legend works. Because I still want the animations to play and hide the item the user taps on, but meanwhile I would also like to setState my app. I experimented with charts.SeriesLegend.customLayout but I couldn't achieve what I wanted and I also don't want a custom layout, I need the default one.
I would like to call a function like this, so I need to know which legends are shown (see gif):
void setChartVariables(input){
setState((){
justified = input.justified;
awaitingJustification = input.awaitingJustification;
unjustified = input.unjustified;
});
}
I created an application using GUIDE called (main). Inside the form (figure), i dragged and dropped many components, one of them is an axes component. When i run the application, it shows allways the same plot. GUIDE generated applications have an opening function, in my case, main_OpeningFcn. I already tried to clear (cla) it in the first line of main_OpeningFcn function, but it first blinks and old plot and then clears it. I am sure it is an old plot, i can recognize it. It seems like this old plot had been saved somewhere and everytime the application starts, it is shown. Is there any cache or something like that?
Maybe you accidently clicked on the save icon in your figure from the gui-window (not guide-window). Now when you open your gui, matlab will not create an empty plot, but will load whatever is saved in the fig-file, that exists beside the m-file for your guide-application.
To solve the issue, you need to delete the figure in your guide-editor, an place a new figure instead. And try to hide the menubar to avoid clicking the save icon again, if your gui is open.
I’m going to build a GUI in MATLAB. This GUI page should do my settings.
I’ve six radio buttons, Camera One to Six. Under these radio buttons I’ve three additional radio buttons, Crop Side, and then under this section I’ve a Crop Percent slider.
What I want is, I need to select camera button five, for example, and then automatically set the latest setting that I’ve done on the radio buttons in Crop Side and Slider.
For example, once I’ve select the Camera Two button and set Crop Side to ‘Left’ and Crop Percent Slider to 12.
The next time I check it, the value of Crop side and Crop percent will be set to the ‘Left’ and 12, respectively.
I don’t know which kind of variables and which syntax model would be more useful for this purpose.
Here are links to my code and figure:
https://www.4shared.com/account/home.jsp?sId=kcxzI7wiO9gxGRtq&changedir=-gDLNzzw
http://cdn.persiangig.com/download/GFJExIPKMO/Works.zip/dl
In your callback function for each button, include piece of code to save the buttons value and then load those values each time you choose a new camera, e.g. if you have click on camera 5 and then click on radiobutton for crop it could look something like this:
function radiobuttonCrop_Callback(hObject,event)
% <Here is the code you have atm>
% Add this code
load('guiSettings.mat') % Loads a .mat file containing your settings
settings.cam5.crop = get(hObject,'Value'); % Updates settings.crop to the current value
save('guiSettings.mat') % Saves the updates
end
When you click on another camera, e.g. camera 3, load the settings for camera 3 as below:
function radiobuttonCamera3_Callback(hObject,handles)
load('guiSettings.mat')
set(handles.radiobuttonCrop,'Value',settings.cam3.Crop)
set(handles.slider,'Value',settings.cam3.Slider)
and so on.
Note: guiSettings.mat is the file name containing the settings. When loading with load('guiSettings.mat') you will get the variable settings contained in the file. settings is a struct containing all cameras and all settings for the cameras.
I hope this helps.
I have a simple question about matlab GUI?
how can i Enable some component visibility in MATLAB GUI figure? For an easy understanding i am using a fgure to explain my problem.
I wanted to do something like.
After Running my Gui. i wanted to show only a specific pushbutton rather all the components
as shown in Figure 1
Once i click on Lets ADD Button the figure 2 should appear
After selecting a number my Other Components should appear as shown in figure 3.
Sorry if my Words are misleading to you as i do not have a good command on technical words.
Thanks..........
You need to detect the event (i.e. press button) and create a function for that.
There you will need to enable the visibility of whatever you want like:
set(handles.pushbutton1,'visible','on')
What is the best/easiest way to choose an image among three with a button.
It will be a button ( or a label, or anything about 40x40) that you click to choose an image. I know normally you use a custom picker, but its only for three images, maybe there is a simpler way. ( a tableview?)
the image will be about 50x50 p on the view.
Could someone give the piece of code for it please?
thanks a lot
Have you looked at UISegmentedControl? You could either use that directly or perhaps present it modally from a button if the space is limited.