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 件のコメント
Max Müller
Max Müller 2014 年 9 月 15 日
going back to GUIDE but Thanks alot

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by