MATLAB开发环境与工具.ppt

上传人:小飞机 文档编号:6511889 上传时间:2023-11-08 格式:PPT 页数:38 大小:292.49KB
返回 下载 相关 举报
MATLAB开发环境与工具.ppt_第1页
第1页 / 共38页
MATLAB开发环境与工具.ppt_第2页
第2页 / 共38页
MATLAB开发环境与工具.ppt_第3页
第3页 / 共38页
MATLAB开发环境与工具.ppt_第4页
第4页 / 共38页
MATLAB开发环境与工具.ppt_第5页
第5页 / 共38页
点击查看更多>>
资源描述

《MATLAB开发环境与工具.ppt》由会员分享,可在线阅读,更多相关《MATLAB开发环境与工具.ppt(38页珍藏版)》请在三一办公上搜索。

1、第三章 MATLAB的开发环境和工具,MATLAB的操作环境 便于开发并与其他软件、硬件进行交互通信,这是MATLAB语言在语法与编程高效简洁之外的另一大优点。程序设计与平台无关,使之可在多种计算机型和操作系统下运行;能够与一些重要的图形、文字编辑器进行交互,将计算结果方便地组织成图文并茂的文章;MATLAB3.X之后,版本的升级主要集中在工具箱的扩展和开发环境的改善。,3.1 MATLAB与其他软件的接口3.1.1 与磁盘操作系统的接口关系1、变量的存储与下载save:将工作空间的变量存入磁盘,load:将磁盘上存储的数据文件取回到MATLAB工作空间中。,Use the functiona

2、l form of SAVE,such as SAVE(filename,var1,var2),when the filename or variable names are stored in strings.See also LOAD,DIARY,FWRITE,FPRINTF,UISAVE,FILEFORMATS.,a=1b=2:5c=magic(3),saveSaving to:matlab.matsave aa a b csave aa a b c-asciisave ac-do a b c-ascii-doublesave ac-ta a b c-ascii-tabs,load:lo

3、ad是save的逆过程,将磁盘是存储的数据文件取回到工作空间中。load与save唯一差别是它不能选择某一个文件中的变量,只能将文件中的全部数据及变量名都下载到工作空间中。,2.工作日志的记录:diary功能:将MATLAB工作过程的全部屏幕文字和数据以文件方式记录下来,成为一个工作记录,默认文件名是diary。格式是文本文件,可由任何文字处理软件打开和修改。diary不能记录MATLAB运行过程中生成的图形。diary ondiary.txtdiary diadia.txt,diary off:结果记录过程;如再次使用diary on或diary filename,新记录的内容将接在原记录的

4、后面,而不冲掉原记录。,3.日期与时间命令日期与时间的相关数据,都是从操作系统中提取。例:计算一个100100的矩阵的求逆运算的时间。t0=clock,y=inv(rand(100,100);etime(clock,t0)t=cputime,y=inv(rand(100,100);cputime-ttic,y=inv(rand(100,100);toc,4.不退出MATLAB环境运行其他软件以!开头的命令表示这是一个dos操作系统的命令。如!dir,3.1.2 与文字处理系统winword的关系1.利用剪贴板进行交互文字图形:图形选项,2.文字编辑器的使用保留字:蓝色;非法字符:鲜红,注释:绿

5、色,引用字符:深红文件扩展名为.m编辑函数文件(以function开头)时,将存储文件名定义为该程序的函数名;自动缩进排版,便于阅读与调试菜单项Debug的各子项提供了程序调试功能。,3.1.3 图形文件的转储 可选择不同的图形格式,并导出图形,实现与其他软件间的接口转换。这些图形不再属于MATLAB文件。,3.1.4 低层输入输出函数库科学计算软件与其它软件系统进行直接的数据交换是十分重要的,这样才能避免人为差错,提高运行效率。输入输出文件:提供一种有效地数据交换方法。,例:在一个二进制文件aaa.bin中写入空间变量xfidl=fopen(aaa.bin,r+)%打开aaa.bin文件,r

6、+表示可读可写,didl为文件标识。N=fwrite(fidl,x,float)%将x以float格式写入fidl文件,返回实际写入的元素个数N。,例:在一个二进制文件aaa.bin中写入空间变量xfidl=fopen(aaa.bin,r+)%打开aaa.bin文件,r+表示可读可写,didl为文件标识。N=fwrite(fidl,x,float)%将x以float格式写入fidl文件,返回实际写入的元素个数N。,从aaa.bin读入一个二进制数,并将它赋值给A:frewind(fidl)fidl=fopen(aaa.bin,r+);%打开aaa.bin文件,r+表示可读可写,didl为文件标

7、识。A=fread(fidl,5,5,float)%将fidl中的前25个数以float格式读出,列成5*5矩阵,并赋值给A。frewind(fidl):倒带命令。文件读写犹如磁带,写入后必须倒带才能重放。,MATLAB还提供:音频信号接口命令图像信号接口命令动态数据交换函数库,3.1.5 MATLAB与C和FORTRAN子程序的动态链接:MATLAB本身是用C语言编写的;科学计算子程序库中的许多经典部分来自FORTRAN程序库。MATLAB可以直接调用经过一定处理的C语言和FORTRAN可执行文件,使执行这些子程序的速度与C语言的FORTRAN语言相同,这些可执行文件的后缀为mex。除MAT

8、LAB已有的mex文件,用户还可以将其它的mex文件加入系统。,3.2 MATLAB的文件管理系统3.2.1 安装后的MATLAB文件管理系统:至少包括4个文件夹:bin:程序所用的二进制文件,包括matlab.exe(MATLAB6.5在binwin32目录中)extern:外部文件help:各种帮助文件;(helppdf_doc下为MATLAB及其工具箱的说明书),toolbox:MATLAB的各种函数库,其下一级子目录为其中的各种工具箱(目录名就是工具箱的名称);通常在MATLAB根目录下,还有一个用户自己的子目录,user或work,用来存放用户自编的应用程序。,3.2.2 MATLA

9、B自身的用户文件格式 程序文件:M文件(后缀为.m),各个工具箱的函数,也多为M文件;数据文件:后缀为.mat(由save命令生成);可执行文件:后缀为.mex,由编译器对M文件编译生成,运行速度远高于直接执行M文件。模型文件(.mdl)和仿真文件(.s):用simulink工具箱生成。,3.2.3 文件管理和搜索路径搜索路径:确定MATLAB管理的文件范围。由启动文件toolboxlocalmatlabrc.m规定。type matlabrc.m if exist(pathdef,file)matlabpath(pathdef);end,pathdef.m中的路径要列到最底层子目录;整个计算

10、机系统中的任何一个底层文件夹,都可以列入MATLAB的搜索路径;这时,这些文件夹中的文件都可以被MATLAB执行;相反,如果程序不在搜索路径中,即使是在MATLAB的目录下,也不能被执行。,在MATLAB 6.x中增加了搜索、设置路径的对话框。,3.2.4 与目录和搜索有关的命令:1.dir DIR List directory.DIR directory_name lists the files in a directory.Pathnames and wildcards may be used.For example,DIR*.m lists all the M-files in the

11、current directory.D=DIR(directory_name)returns the results in an M-by-1 structure with the fields:name-filename date-modification date bytes-number of bytes allocated to the file isdir-1 if name is a directory and 0 if not,2.CD:Change current working directory.CD directory-spec sets the current dire

12、ctory to the one specified.CD.moves to the directory above the current one.CD,by itself,prints out the current directory.WD=CD returns the current directory as a string.,3.delete:DELETE Delete file or graphics object.DELETE file_name deletes the named file from disk.Wildcards may be used.For example

13、,DELETE*.p deletes all P-files from the current directory.Use the functional form of DELETE,such as DELETE(file)when the file name is stored in a string.DELETE(H)deletes the graphics object with handle H.If the object is a window,the window is closed and deleted without confirmation.,4.MKDIR Make ne

14、w directory.SUCCESS,MESSAGE,MESSAGEID=MKDIR(PARENTDIR,NEWDIR)makes a new directory,NEWDIR,under the parent,PARENTDIR.While PARENTDIR may be an absolute path,NEWDIR must be a relative path.When NEWDIR exists,MKDIR returns SUCCESS=1 and issues to the user a warning that the directory already exists.,5

15、.COPYFILE:Copy file or directory.SUCCESS,MESSAGE,MESSAGEID=COPYFILE(SOURCE,DESTINATION,MODE)copies the file or directory SOURCE to the new file or directory DESTINATION.Both SOURCE and DESTINATION may be either an absolute pathname or a pathname relative to the current directory.When the MODE is set

16、,COPYFILE copies SOURCE to DESTINATION,even when DESTINATION is read-only.The DESTINATIONs writable attribute state is preserved.See NOTE 1.,6.WHAT List MATLAB-specific files in directory.The command WHAT,by itself,lists the MATLAB specific files found in the current working directory.Most data file

17、s and other non-MATLAB files are not listed.Use DIR to get a list of everything.The command WHAT DIRNAME lists the files in directory dirname on the MATLABPATH.It is not necessary to give the full path name of the directory;a MATLABPATH relative partial pathname can be specified instead(see PARTIALP

18、ATH).For example,what general and what matlab/general both list the M-files in directory toolbox/matlab/general.,W=WHAT(directory)returns the results of WHAT in a structure array with the fields:path-path to directory m-cell array of m-file names.mat-cell array of mat-file names.mex-cell array of me

19、x-file names.mdl-cell array of mdl-file names.p-cell array of p-file names.classes-cell array of class names.,7.WHICH Locate functions and files.WHICH FUN displays the full pathname of the function with the name FUN.Variables in the workspace,built-in functions,loaded Simulink models,or methods in J

20、ava classes display a message indicating that FUN is a variable,built-in function,a Simulink model,or a method in one or more Java classes.WHICH only finds the methods of those Java classes that are on the classpath.,8.LOOKFOR Search all M-files for keyword.LOOKFOR XYZ looks for the string XYZ in th

21、e first comment line(the H1 line)of the HELP text in all M-files found on MATLABPATH.For all files in which a match occurs,LOOKFOR displays the H1 line.,3.2.5 搜索顺序MATLAB在执行程序时,将字符串按以下顺序与已有记录相比较:,用户在定义变量名和程序名时,要避免与MATLAB的内部变量与函数重名。,3.3 MATLAB的开发环境3.3.1 桌面系统的内容MATLAB6.x将多种开发工具集成为MATLAB桌面系统,该系统由桌面平台及组件

22、组成。包括8个组成部分。,1.命令窗口(Command Window)2.历史命令窗口(Command History):记录并显示本次工作进程中曾输入的全部行命令。3.资源目录本(Launch Pad):收集所有的MATLAB产品说明、演示以及帮助信息的目录,以便用户调用查阅。4.当前路径浏览器(Current Directory):显示系统当前目录下的MATLAB文件信息,包括文件名,文件类型,最后修改以及文件的说明信息。,5.帮助浏览器(Help Browser):显示帮助信息,用户还可以加入自己的注解,形成帮助信息。6.工作空间浏览器(Workspace Browser):显示所有目前保存在内存中的变量的名称,数学结构,字节数和类型。7.数组编辑器(Array Editor):8.程序编辑调试器(Editor Debugger):,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号