Working with uicontrol / Working wihout GUIDE
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Max Müller
le 15 Sep 2014
Réponse apportée : Robert Cumming
le 15 Sep 2014
Hey Guys,
i try to work without GUIDE to develop my matlab skills: Can u pls tell me: what is worng here.
function CalculationOptions (InputData)
%Figure
handles.newFigure = figure('tag','CalculationOptions','name','CalculationOptions','MenuBar', 'None', 'NumberTitle', 'off','Position',[800 400 270 600]);
%RadioButton
handles.MinRadioButton = uicontrol('style','radiobutton',.....
hadnles.MaxRadioButton = uicontrol('style','radiobutton',.....
handles.MeanRadioButton = uicontrol('style','radiobutton',.....
handles.PositionRadioButton = uicontrol('style','radiobutton',....
handles.PowerRadioButton = uicontrol('style','radiobutton',...
handles.OwnRadioButton = uicontrol('style','radiobutton',.....
%Editbox
handles.OwnCalculationEditbox = uicontrol('style','edit',.....
%Button
handles.CalculateButton = uicontrol('style','pushbutton',......
% Callbacks
set(handles.OwnRadioButton,'Callback',@SetEnableProperty);
set(CalculateButton,'Callback',@Calculate)
function SetEnableProperty(hObject,evendata,handles)
if get(handles.OwnRadioButton,'Value') == 1
disp('OK')
end
2 commentaires
Adam
le 15 Sep 2014
What do you expect to be wrong?
I can't paste your example into my Matlab due to all the unfinished uicontrols, but you did spell 'handles' as 'hadnles' on the 2nd line under %RadioButton
Michael Haderlein
le 15 Sep 2014
I'm not sure if you have cropped the lines for better readability or if the lines are incomplete?
I haven't worked with gui for a while but as far as I remember, the radio buttons should be in a uibuttongroup parent (I guess the MinRadioButton and the PowerRadioButton are independent from each other).
Also, an "end" is missing.
Réponse acceptée
Sean de Wolski
le 15 Sep 2014
When working outside of GUIDE, the handles structure is not implicitly passed in to the callback. Just the source and event data are. The easiest thing to do here would be to nest SetEnableProperty so that it has access to handles from the parent workspace:
Minimal working example:
function CalculationOptions (InputData)
%Figure
handles.newFigure = figure('tag','CalculationOptions','name','CalculationOptions','MenuBar', 'None', 'NumberTitle', 'off','Position',[800 400 270 600]);
%RadioButton
handles.OwnRadioButton = uicontrol('style','radiobutton');
set(handles.OwnRadioButton,'Callback',@SetEnableProperty);
function SetEnableProperty(hObject,evendata)
if get(handles.OwnRadioButton,'Value') == 1
disp('OK')
end
end
end
Kudos for working outside of GUIDE :)
Plus de réponses (1)
Robert Cumming
le 15 Sep 2014
I see this has alreayd been answered(and accepted), but my advice is dont give up.
Your GUIs will be a lot better and you can do so much more with them when you learn how to write them on your own (see here for some examples of my own commandline GUI framework - I can provide a lot more if interested)
I've been writing matlab GUI's for over 10 years - all from commandline.
There is a number of ways to get access to the uicontrol properties, for example:
1. pass a handle to your GUI into your callbacks
2. use setappdata and getappdata to store the handle information
3. create a class where you store your uicontrol handles for your methods to access
0 commentaires
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!