Working with uicontrol / Working wihout GUIDE

1 visualización (últimos 30 días)
Max Müller
Max Müller el 15 de Sept. de 2014
Respondida: Robert Cumming el 15 de Sept. de 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 comentarios
Adam
Adam el 15 de Sept. de 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
Michael Haderlein el 15 de Sept. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 15 de Sept. de 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 :)

Más respuestas (1)

Robert Cumming
Robert Cumming el 15 de Sept. de 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

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by