0
点赞
收藏
分享

微信扫一扫

MATLAB-基础知识总结


disp函数:

disp函数会直接将内容输出在Matlab命令窗口中  1.输出字符串:  Matlab命令窗口输入如下代码

disp(‘my test’)

Matlab命令窗口输出如下

my test

2.输出数字:  Matlab命令窗口输入如下代码

test=12;  disp(test)

Matlab命令窗口输出如下

12

3.同时输出字符串和数字:  Matlab命令窗口输入如下代码

test=3;  disp([‘my test=’,num2str(test)])

Matlab命令窗口输出如下

my test=3

求矩阵的最大最小:

方法一

min(min(y))  ;  max(max(y))

方法二

min(y(:))  ;   max(y(:))

subplot函数:

功能

分割figure,创建子坐标系

语法

h = subplot(m,n,p) or subplot(mnp)
subplot(m,n,p,'replace')
subplot(m,n,P)
subplot(h)
subplot('Position',[left bottom width height])
subplot(..., prop1, value1, prop2, value2, ...)
h = subplot(...)

描述

h = subplot(m,n,p)/subplot(mnp) 将figure划分为m×n块,在第p块创建坐标系,并返回它的句柄。当m,n,p<10时,可以简化为subplot(mnp)或者subplot mnp 

(注:subplot(m,n,p)或者subplot(mnp)此函数最常用:subplot是将多个图画到一个平面上的工具。其中,m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一行的,一共m行,如果第一个数字是2就是表示2行图。p是指你现在要把曲线画到figure中哪个图上,最后一个如果是1表示是从左到右第一个位置。 )

subplot(m,n,p,'replace')如果所指定的坐标系已存在,那创建新坐标系替换它 

subplot(m,n,P)此时p为向量,表示将P中指定的小块合并成一个大块创建坐标系,P中指定的小块可以不连续,甚至不相连。 

比如subplot(2,3,[2 5])表示将第2和5小块连成一个大块;subplot(2,3,[2 6])由于2和6不连续也不相连,此时表示将第2、3、5和6四块连成一个大块,相当于subplot(2,3,[2 3 5 6]) 

subplot(h) 将坐标系h设为当前坐标系,相当于axes(h)

subplot('Position',[left bottom width height])在指定位置创建一个新坐标系,等效于axes('Position',[left bottom width height]) 

subplot(..., prop1, value1, prop2, value2, ...)在创建坐标系时,同时设置相关属性,axes属性参见附录 

h = subplot(...) 返回所创建坐标系的句柄 

注意

1)使用subplot新建的axes块如果与已存在块重叠,MATLAB将删除已存在的axes并创建新的axes,除非已存在和需要创建的axes完全重合(此时相当于将它置为当前坐标系),此时如果想删除重建的话,需要使用'replace'参数 

2)subplot(1,1,1)清空当前窗口所有坐标系对象,并创建一个默认的坐标系。注意此时subplot(1,1,1)和subplot(111)不完全等效,subplot(111)执行完以后,没有任何直观上的反应,它只是促使figure在下次调用绘图命令之前执行清空图形命令clf reset,接着创建一个默认坐标系。也就是说subplot(111)相当于将subplot(1,1,1)的操作分开了。由于subplot(111)执行完并没有创建新坐标系,故没法返回句柄,也就是说h=subplot(111)是错误的

举报

相关推荐

0 条评论