给出我今天学到的两个例子来说明两种用法:
(1)set(h, 'StartFcn', @myfile)型
function [varargout] = XIE_bwmorphfig(Size, varargin)
h = figure('name', 'test', 'numbertitle', 'off', 'menubar', 'none', ...
'units', 'normalized', 'position', [0.14 0.18 0.72 0.64]);
Matrix = [0.5 0.5 0.5];
uipanel('position', [0 Matrix], 'backgroundcolor', [0.8 0.8 0.8]);
axes1 = subplot('position', [0 Matrix]);
set(axes1, 'visible', 'on');
uipanel('position', [0.5 Matrix], 'backgroundcolor', [0.8 0.8 0.8]);
axes2 = subplot('position', [0.5 Matrix]);
set(axes2, 'visible', 'on');
radio1 = uicontrol('style', 'radio', 'Tag', 'radio1', ...
'units', 'normalized', 'position', [0.1 0.3875 0.2 0.1], ...
'backgroundcolor', [0.8 0.8 0.8], ...
'string', 'doit', 'FontSize', 16, ...
'callback', {@doit,axes1});
global im;
im = imread('I.jpg');
imshow(im);
function doit(src,eventdata,arg1)
global im ;
axes(arg1);
im = rgb2gray(im);
imshow(im);
(2)set(h, 'StartFcn', 'myfile')型
function [] = XIE_bwmorphfig(varargin)
figure('name', 'test', 'numbertitle', 'off', 'menubar', 'none', ...
'units', 'normalized', 'position', [0.14 0.18 0.72 0.64]);
Matrix = [0.5 0.5 0.5];
uipanel('position', [0 Matrix], 'backgroundcolor', [0.8 0.8 0.8]);
axes1 = subplot('position', [0 Matrix]);
set(axes1, 'visible', 'on');
global axes2 ;
uipanel('position', [0.5 Matrix], 'backgroundcolor', [0.8 0.8 0.8]);
axes2 = subplot('position', [0.5 Matrix]);
set(axes2, 'visible', 'on');
handles.radio1 = uicontrol('style', 'radio', 'Tag', 'radio1', ...
'units', 'normalized', 'position', [0.1 0.3875 0.2 0.1], ...
'backgroundcolor', [0.8 0.8 0.8], ...
'string', 'doit', 'FontSize', 16, ...
'callback', 'doit');
global im;
axes(axes1);
im = imread('01.jpg');
imshow(im);
function doit()
global im axes2 ;
axes(axes2);
im = rgb2gray(im);
imshow(im);
这用需要把回调函数和主程序分别存储。这两个例子由hotboy和zhenghui提供,希望能遇到同样问题的朋友一点启发!