matlab的基本语法规则_【经验交流】matlab自定义回调函数语法规则

给出我今天学到的两个例子来说明两种用法:

(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提供,希望能遇到同样问题的朋友一点启发!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值