Difference in running GUI from GUIDE and from the Desktop?
2 views (last 30 days)
Show older comments
One issue that I'm having is with multiple places in SelectionChangeFcn callbacks in uibuttongroup objects.
I have lines of code, all similar to this:
set(handles.cmd_step_delay, 'Enable', 'off');
where cmd_step_delay is a edit style object inside of a uibuttongroup. The goal for this line of code is that I have multiple Radiobuttons in the uibuttongroup, and each has an associated edit box or edit boxes for certain parameters. I only want the associated edit boxes enabled when that particular radio button is selected.
If I first open up my figure in GUIDE, and press the Play button, there are no issues with this.
If, however, I open the figure from the desktop, and attempt to click on one of the radio buttons that does this, I get the error: "Attempt to reference field of non-structure array."
I want to be able to give this to an end user who will just run the form, I don't want them to have to open GUIDE just to run this. Is there something I'm doing wrong?
Here's the entire code for one of the callbacks, but there's not much to it:
function CMD_patt_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in CMD_patt
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(eventdata.NewValue,'String'), 'Step') == 1
set(handles.cmd_step_delay, 'Enable', 'on');
set(handles.cmd_step_ang, 'Enable', 'on');
else
set(handles.cmd_step_delay, 'Enable', 'off');
set(handles.cmd_step_ang, 'Enable', 'off');
end
Thank You.
3 Comments
Matt Fig
on 6 Sep 2012
You don't open a GUIDE GUI by opening the figure. You open a GUIDE GUI by calling the name of the GUI at the command line...
Accepted Answer
Image Analyst
on 6 Sep 2012
Edited: Image Analyst
on 6 Sep 2012
There should be no difference between running via the green triangle in GUIDE and the green triangle in MATLAB. Don't run it by double-clicking the .fig filename in the file browser panel in MATLAB. You could try replacing this:
if strcmp(get(eventdata.NewValue,'String'), 'Step') == 1
with this
if get(handles.radioButton1, 'Value')
use whatever tag for handles.radioButton1 that corresponds to the radio button you want to check. This will check whether the radio button is selected or not. It's a more direct way of checking it than checking for the text on the radio button.
I think that eventdata.NewValue is "handle of the currently selected object" which should be just whatever radio button you just clicked on. This could be either selected or unselected (true or false) so it doesn't make sense to check the text of the radio button you just clicked on. That doesn't tell you anything about the true or false state of the radio button. It does make sense to check the actual value(s) of the radio button(s). Based on the values of the radio buttons you can enable and disable certain other controls, like edit fields.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!