|
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
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|