首 页 - ┆ 小小说社会科学搜榜改进建议哲学宗教政治法律文化科教语言文字医学管理资源艺术资料数理化天文地球专业技术教育资源建筑房地产
当前位置:e书联盟 > 专业技术 > 机械化工 > 机械化工word
MATLAB中M文件例子.doc
运行环境:Win9X/Win2000/WinXP/Win2003/
技术语言:简体中文
技术类型:国产软件 - 机械化工 - 机械化工word
授权方式:共享版
技术大小:283 KB
推荐星级:
更新时间:2019-12-30 16:43:29
联系方式:暂无联系方式
官方主页:Home Page
解压密码:点击这里
  • 好的评价 此技术真真棒!就请您
      0%(0)
  • 差的评价 此技术真差劲!就请您
      100%(1)

MATLAB中M文件例子.doc介绍

20.11 M文件例子
	精通MATLAB工具箱含有许多实用函数,它们可以验证本章的许多概念。这些函数的基本部分已经在二维和三维图形这些章阐述过了。有了前面对句柄图形的讨论,我们现在可以更彻底地讨论这些函数。
	最简单的精通MATLAB工具箱的函数之一提出了一个共同的问题。MATLAB函数gcf返回当前图形的句柄。但是,它有一个副作用。如果图形不存在,gcf就创建一个,并返回它的句柄。如果想寻找一个图形是否存在于头一个位置,要是没有,又不得不创建,怎么办?函数mmgcf正好实现由其内容所描述的工作。
	function HF=mmgcf
	%MMGCF Get Current Figure if it Exists.
	%  MMGCF returns the handle of the current figure if it exists.
	%  If no current figure exists,MMGCF returns an empty handle.
	%
	%  Note that the function GCF is different.It creates a figure and returns its handle if it does not 	%  exist.
	%  Copyright  (c)  1996 by Prentice-Hall,Inc.
	Hf=get(0, ‘Children’ );  %  check for figure children
	if isempty(Hf)
		return
	else
		Hf=get(0, ‘CurrentFigure’ );
	end
	函数mmgcf首先检查根对象的子对象的图形是否存在,如至少有一个图形对象时,根对象的 ‘CurrentFigure’ 属性就返回当前的图形。
	函数mmgca为坐标轴对象执行同样的功能,如同在它的M文件内所描述的那样。
	function Ha=mmgca
	%MMGCA Get Current Axes if it exists.
	%  MMGCA returns the handle of the current axes if it exists.
	%  If no current axes exists,MMGCA returns an empty handle.
	%
	%  Note that the function GCA is diffent.It create a figure and an axes and returns the axes 	%  handle if they do not exist.
	%  Copyright  (c)  1996 by Prentice-Hall,Inc.
	Ha=findobj(0, ‘Type’ , ‘axes’ );
	if isempty(Ha)
		return
	else
		Ha=get(get(0, ‘CurrentFigfure’ ), ‘CurrentAxes’ );
	end
	由于函数gco已经表现出当对象不存在时返回空矩阵的行为特性,就不需要函数mmgco了。
	在精通MATLAB工具箱中的另一个函数是mmzap,在二维图形那一章里已作过介绍。如下M文件中所示,它使用mmgcf作错误检查,与findobj和get一起删除一个指定的图形。
	function mmzap(arg)
	%MMZAP Delete graphics object using mouse.
	%  MMZAP waits for a mouse click on an object in a figure window and deletes the object.
	%  MMZAP or MMZAP text erases text objects.
	%  MMZAP axes erases axes objects.
	%  MMZAP line erases line objects.
	%  MMZAP surf erases surface objects.
	%  MMZAP patch erases patch objects.
	%
	%  Clicking on an object other than the selected type or striking a key on the keyboard aborts 	%  the command.
	%  Copyright  (c)  1996 by Prentice-Hall,Inc.
	if nargin 1,arg= ‘text’ ;end
	Hf=mmgcf;
	if isempty(Hf),error( ‘No Figure Available.’ ),end
	if length(findobj(0, ‘Type’ , ‘figure’ ))==1
		figure(Hf)  %  bring only figure forword
	end
	key=waitforbuttonpress;  %  pause untill user takes some action
	if key  %  key on keyboard pressed
		return  %  take no action
	else  %  object selected
		object=gco  %  get object selected by buttonpress
		type=get(object, ‘Type’ );
		if all(type(1:4)==arg(1:4))  %  delete only if  ‘Type’  is correct
			delete(object)
		end
	end
	在编写句柄图形函数的M文件时,函数mmzap描述了一种很有用的技术。它利用函数waitforbuttonpress和gco的结合用鼠标来获取所选定对象的句柄。waifortbuttonpress是一个MATLAB内置函数,它的功能是等待鼠标点击或按键。它的帮助文本如下:
	? help waitforbuttonpress
	WAITFOR BUTTONPRESS Wait for key/buttonpress over figure.
		T= WAITFOR BUTTONPRESS stops program execution untill a key or mouse button is 		pressed over a figure window.Returns 0 when terminated by a mouse buttonpress,or 1 		when terminated by a keypress.Additional information about the terminating event is 			available f
MATLAB中M文件例子.doc

下载此电子书资料需要扣除0点,

电子书评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
·上一技术:MATLAB入门教程.doc
·下一技术:MBR方案(500吨).doc

下载说明

* 即日起,本站所有电子书免费、无限量下载下载,去掉了每日50个下载的限制
* 本站尽量竭尽努力将电子书《MATLAB中M文件例子.doc》提供的版本是完整的,全集下载
* 本站站内提供的所有电子书、E书均是由网上搜集,若侵犯了你的版权利益,敬请来信通知我们!
Copyright © 2005-2020 www.book118.com. All Rights Reserved