Dynamic popup menu choices in GUIDE

2 views (last 30 days)
Sergei
Sergei on 14 Jan 2015
Commented: Sergei on 15 Jan 2015
I am attempting to make dynamic popup menu fields in a GUI made with GUIDE.
My intention is to change the fields when a specific popup choice is picked in another popup menu. The popup menus are initially populated with information from GUIDEs Property Inspector.
This codes works when launching the GUI using after pressing the "play" button in GUIDE. It does not work when launching the figure on its own.
  • * *The error received is "Attempt to reference field of non-structure array."
Why does this happen? How can I make it work like it works when launched from GUIDE?* * *
The relevant code; solver_settings doesn't do anything interesting. From this it can be seen that the intention is to have a certain range of algorithm options available to the user depending on what solver type he picks, because not all of them are relevant to each other. Hence L-M would not be available to fmincon or Genetic Algorithm.
function solver_type_Callback(hObject, eventdata, handles)
% hObject handle to solver_type (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns solver_type contents as cell array
% contents{get(hObject,'Value')} returns selected item from solver_type
set1 = {'interior-point';'active-set';'sqp';'trust-region-reflective'};
set2 = {'trust-region-reflective','levenberg-marquardt'};
set3 = {'In progress'};
val = get(hObject,'Value');
str = get(hObject,'String');
switch str{val}
case 'fmincon'
assignin('base','optimalg',1);
set(handles.solver_settings,'String',set1,'Value',1);
case 'lsqnonlin'
assignin('base','optimalg',2);
set(handles.solver_settings,'String',set2,'Value',1);
case 'Genetic Algorithm'
assignin('base','optimalg',3);
set(handles.solver_settings,'String',set3,'Value',1);
end
guidata(hObject, handles)
  1 Comment
Sara
Sara on 14 Jan 2015
Does matlab give you the line where the error occur? What does that line say in case?

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 15 Jan 2015
Sergei - a GUI, as created through GUIDE, can only be launched in one of three ways: through GUIDE, through the MATLAB editor (so you press the run button while editing the m file if the GUI), or from the Command Window by calling the GUI by name
>> myGui
where you have a myGui.m and myGui.fig files. You cannot double-click on the figure file to launch the GUI because this method will only open the GUI and display its controls. It will not initialize the necessary or appropriate members (like handles) and so you will observe errors like you have described above.
  2 Comments
Image Analyst
Image Analyst on 15 Jan 2015
OR by typing F5 when the code is the active code window in the editor. Explain exactly what "launching the figure on its own" means to you, Sergei - which of those 4 valid methods or one invalid method did you use?
Sergei
Sergei on 15 Jan 2015
Thank you - I had the impression that the GUI is meant to be launched through the .fig and not through the function file.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!