GUI Self-Replicating Problem when Radio Button Clicked

I am working on a project which requires the user be able to switch between graphs. For ease of use, I am attempting to use Radio Buttons to switch between graphs. In the callbacks for the selection of the radio buttons, I refer to outside scripts rather than placing the entire code within the radio buttons as a means of keeping things simpler. However, instead of running the scripts when a radio button is selected, another window identical to the original GUI opens. I can't figure out why this is and would like very much for the embedded axes to be updated with the desired graph rather than another GUI window open... Any suggestions?

1 Comment

Alright, so the GUI is no longer self-replicating. Thanks to Image Analyst for helping me to realize that the radio button values were not being correctly checked and that the call to other script files needed to be executed in the button group callback.
If anyone else is having any similar problems, check the radio button value check, where the script files are being called, and drop the .m .

Sign in to comment.

 Accepted Answer

Hard to say without looking at the callback, but it appears that the gui is calling itself. That's about all we can say without seeing the code. Attach the m and fig files if you want more advice.

4 Comments

Sorry, so the callback for the radio buttons is really quite simple. It looks like this:
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over Environ2.
function Environ2_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to Environ2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Environ2.m
where Environ2.m is the script containing the plot data for the graph. In the script file, there is no specification of which figure it should be plotted on, is there a way to specify in the callback to plot to the Axes in the GUI?
The radio buttons are in a button group, but the callback is initiated by pressing the radio button and not upon changing the button group. Environ2.m simply contains definitions of variables and plot code like plot(X + 5 r, Y + 2 cos (ang)
etc.
Please read this and then fix the formatting http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup and I'll look at it tomorrow. Also say whether the radio buttons are in a group.
I don't understand. When buttons are in a group, when you click on one, it deselects the others, and you execute the group callback, not the individual radio buttons' callbacks. But it sounds like you are executing just one individual radio button's callback.
Also, you are calling Environ2.m. I never add the .m when calling an m-file function. Maybe that's okay, I don't know, but it's certainly not the norm if it is allowable. I know of no one who adds the .m after calling an m-file.
Next, you're calling Environ2 regardless of the state of the radio button. You never check the radio button's value - you just call the function. If so, why you you even using a radio button? The whole point of using a radio button is to do things differently depending on whether that radio button is selected or not. You might as well use a push button instead if you're just going to call Environ2 no matter what.
I'm very new to MatLab, so I don't entirely know what I'm doing. I can try moving the different scripts to the group callback. I only posted one of the callbacks; the others are more of the same, except calling out different script files so as to plot different graphs. There are 5 total radio buttons and 5 different graphs. I'll try dropping the .m, hopefully that will solve it. Thank you for your help and being patient with someone who clearly doesn't know what they're doing :)

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 9 Mar 2014

Edited:

on 9 Mar 2014

Community Treasure Hunt

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

Start Hunting!