Thread Subject: GUIand callback in same .m file

Subject: GUIand callback in same .m file

From: Madhu Shurpali

Date: 30 Jul, 2007 09:10:54

Message: 1 of 3

Hello Everybody,

I have defined a GUI with consisting of a couple of radio buttons.
  I am trying to define the callback to the a Radio Buttons in the
same .m file. I got to know that the baset way to do it is by using
function handles. But I still couldn't. Can somebdy look at the
following code and let me know what needs to be done..

Thanks..

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function GUI

%%%%%% GUI for Radio Button %%%%%%%%%%%%
BaseFigure = figure('color', [0.8 0.8 0.8],...
            'Name','Test Edit Box',...
            'NumberTitle','off',...
            'position',[520 220 720 270],...
            'Tag','Fig');
        
Current_Folder = uicontrol('Parent',BaseFigure,...
                     'Units','points',...
                     'Backgroundcolor',[0.8 0.8 0.8],...
                     'position',[20 70 200 100],...
                     'string','mat Files from current Folder',...
                     'style','radiobutton',...
                     'callback',...
                     ' @read(1) ',... %I am trying to call the
function 'read' defined at
                     'Tag','CurrentFolderRadiobutton');
        
All_Folders = uicontrol('Parent',BaseFigure,...
                     'Units','points',...
                     'Backgroundcolor',[0.8 0.8 0.8],...
                     'position',[200 70 300 100],...
                     'string','mat Files from All Folder',...
                     'style','radiobutton',...
                     'callback',...
                     ' @read(2); ',...
                     'Tag','All_FoldersRadiobutton');

Close_pushButton = uicontrol('parent',BaseFigure,...
                     'style','push',...
                     'position',[120 50 170 60],...
                     'string','Done',...
                    'callback','close');
end
                
function rear_out = read(x)
  Rear_out = x
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Subject: GUIand callback in same .m file

From: David

Date: 30 Jul, 2007 14:27:00

Message: 2 of 3

"Madhu Shurpali" <madhu.shurpali@gm.com> wrote in message <ef5f19e.-1@webcrossing.raydaftYaTP>...
> Hello Everybody,
>
> I have defined a GUI with consisting of a couple of radio buttons.
> I am trying to define the callback to the a Radio Buttons in the
> same .m file. I got to know that the baset way to do it is by using
> function handles. But I still couldn't. Can somebdy look at the
> following code and let me know what needs to be done..
>

i don't think its that simple. have you reviewed the help sections on 'assigning a callback property string'? in my older version it requires a string like:
my_gui('pushbutton1_Callback',gcbo,[],guidata(gcbo))
where you plug in the name of your gui function in 'my_gui' and the function in place of the 'pushbutton1_Callback'.
then the function definition has to look like:
function pushbutton1_Callback(hObject, eventdata, handles)

Subject: GUIand callback in same .m file

From: Scott Frasso

Date: 30 Jul, 2007 11:02:09

Message: 3 of 3

Try this,

To pass the function handle 'read' as a callback it must be written as
@read, not as a string. You could pass a string of commands to run as a
callback; however it is not a good practice.

For this version of your code the radio buttons Current_Folder and
All_Folders must be within the scope of the callback function in order to
work, this is why I used nested functions.

%%Code

function GUI


BaseFigure = figure('color', [0.8 0.8 0.8],...

'Name','Test Edit Box',...

'NumberTitle','off',...

'position',[520 220 720 270],...

'Tag','Fig');


Current_Folder = uicontrol('Parent',BaseFigure,...

'Units','points',...

'Backgroundcolor',[0.8 0.8 0.8],...

'position',[20 70 200 100],...

'string','mat Files from current Folder',...

'style','radiobutton',...

'callback',@read,... %I am trying to call the function 'read' defined at

'Tag','CurrentFolderRadiobutton');


All_Folders = uicontrol('Parent',BaseFigure,...

'Units','points',...

'Backgroundcolor',[0.8 0.8 0.8],...

'position',[200 70 300 100],...

'string','mat Files from All Folder',...

'style','radiobutton',...

'callback',@read,...

'Tag','All_FoldersRadiobutton');


Close_pushButton = uicontrol('parent',BaseFigure,...

'style','push',...

'position',[120 50 170 60],...

'string','Done',...

'callback','close');


function rear_out = read(event,data)

if get(Current_Folder,'Value');

rear_out = 'Current Folder';

elseif get(All_Folders,'Value');

rear_out = 'All Folders';

end

end

end

%%

"Madhu Shurpali" <madhu.shurpali@gm.com> wrote in message
news:ef5f19e.-1@webcrossing.raydaftYaTP...
> Hello Everybody,
>
> I have defined a GUI with consisting of a couple of radio buttons.
> I am trying to define the callback to the a Radio Buttons in the
> same .m file. I got to know that the baset way to do it is by using
> function handles. But I still couldn't. Can somebdy look at the
> following code and let me know what needs to be done..
>
> Thanks..
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> function GUI
>
> %%%%%% GUI for Radio Button %%%%%%%%%%%%
> BaseFigure = figure('color', [0.8 0.8 0.8],...
> 'Name','Test Edit Box',...
> 'NumberTitle','off',...
> 'position',[520 220 720 270],...
> 'Tag','Fig');
>
> Current_Folder = uicontrol('Parent',BaseFigure,...
> 'Units','points',...
> 'Backgroundcolor',[0.8 0.8 0.8],...
> 'position',[20 70 200 100],...
> 'string','mat Files from current Folder',...
> 'style','radiobutton',...
> 'callback',...
> ' @read(1) ',... %I am trying to call the
> function 'read' defined at
> 'Tag','CurrentFolderRadiobutton');
>
> All_Folders = uicontrol('Parent',BaseFigure,...
> 'Units','points',...
> 'Backgroundcolor',[0.8 0.8 0.8],...
> 'position',[200 70 300 100],...
> 'string','mat Files from All Folder',...
> 'style','radiobutton',...
> 'callback',...
> ' @read(2); ',...
> 'Tag','All_FoldersRadiobutton');
>
> Close_pushButton = uicontrol('parent',BaseFigure,...
> 'style','push',...
> 'position',[120 50 170 60],...
> 'string','Done',...
> 'callback','close');
> end
>
> function rear_out = read(x)
> Rear_out = x
> end
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com