Working with uicontrol / Working wihout GUIDE
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2014-9-15
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
2014-9-15
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.
采纳的回答
Sean de Wolski
2014-9-15
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 :)
更多回答(1 个)
Robert Cumming
2014-9-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!