Working with uicontrol / Working wihout GUIDE

조회 수: 1 (최근 30일)
Max Müller
Max Müller 2014년 9월 15일
답변: Robert Cumming 2014년 9월 15일
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
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
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
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
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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by