1.函数句柄
(1)函数句柄主要有以下4个用途:
①可以将一个函数传递给另一个函数。
②可以捕获一个函数的数值供下一次使用。
③可以在正常范围外调用函数。
④可以将函数句柄以.mat文件类型保存,供下一次MATLAB运行时使用。
(2)在函数名前加一个“@”符号就可以建立一个函数句柄,一旦创建一个函数句柄,就可以通过函数句柄调用函数。函数句柄包含函数保存的绝对路径,用户可以从任何位置调用该函数。
close all; clear all; clc; %关闭所有图形窗口,清除工作空间所有变量,清空命令行 fhandle=@sin; %建立一个函数句柄 y1=fhandle(2*pi); %用函数句柄调用函数 y2=sin(2*pi); %直接调用函数
workplace中的各项value

(3)MATLAB提供一些与函数句柄相关的函数:
| 函数 | 说明 |
| func2str(fhandle) | 将函数句柄转换为字符串 |
| str2func(‘str‘) | 将字符串转换为函数句柄 |
| functions(fhandle) | 返回包含函数信息的结构体变量 |
| isa(a,‘funhandle‘) | 判断是否为函数句柄 |
| isequal(fhandle1,fhandle2) | 判断两个函数句柄是否对应同一函数 |
close all; clear all; clc; %关闭所有图形窗口,清除工作空间所有变量,清空命令行 f1=@help; %创建函数句柄 s1=func2str(f1); %将函数句柄转换成字符串 f2=str2func(‘help‘); %将字符串转换成函数句柄 a1=isa(f1,‘function_handle‘); %判断f1是否为函数句柄 a2=isequal(f1,f2); %判断f1和f2是否指向同一函数 a3=functions(f1); %获取f1信息
让我们来看看a3的取值:

2.结构类型
(1)结构类型的建立
MATLAB提供两种方法建立结构体,用户可以直接给结构成员变量赋值建立结构体,也可以利用函数struct()建立结构体。
close all; clear all; clc; %关闭所有图形窗口,清除工作空间所有变量,清空命令行
stu(1).name=‘LiMing‘; %直接创建结构体stu
stu(1).number=‘20120101‘;
stu(1).sex=‘f‘;
stu(1).age=20;
stu(2).name=‘WangHong‘;
stu(2).number=‘20120102‘;
stu(2).sex=‘m‘;
stu(2).age=19;
student=struct(‘name‘,{‘LiMing‘,‘WangHong‘},‘number‘,{‘20120101‘,‘20120102‘},‘sex‘,{‘f‘,‘m‘ },‘age‘,{20,19});
%应用struct函数创建结构体student
stu;
stu(1);
stu(2);
student;
student(1);
student(2);
在创建结构体变量的同时,对成员变量进行了赋值;然后利用函数struct()创建结构体student,其中包含4个成员变量与stu相同;最后通过函数stu(1)、sut(2)、student(1)和student(2)显示结构体变量中成员变量的具体数值。
(2)结构类型的操作
| 函数 | 说明 |
| fieldnames(s) | 获取指定结构体所有成员名 |
| getfield(s,‘field‘) | 获取指定成员内容 |
| isfield(s,‘field‘) | 判断是否是指定结构体中的成员 |
| orderfields(s) | 对成员按结构数组重新排序 |
| rmfield(s,‘field‘) | 删除指定结构体中的成员 |
| setfield(s,‘field‘,value) | 设置结构体成员内容 |
3.细胞数组类型
(1)细胞数组类型的建立
MATLAB提供两种方法,一种是直接赋值,一种是用函数cell()创建。因为细胞数组是MATLAB提出的一个新概念,这里就稍微多讲一点。
close all; clear all; clc; %关闭所有图形窗口,清除工作空间所有变量,清空命令行
student{1,1}={‘LiMing‘,‘WangHong‘}; %直接赋值法建立细胞数组
student{1,2}={‘20120101‘,‘20120102‘};
student{2,1}={‘f‘,‘m‘};
student{2,2}={20,19};
student;
student{1,1};
student{2,2};
cellplot(student); %显示细胞数组结构图
%%第二种方法:用函数cellplot()画出student细胞数组结构图
close all; clear all; clc; %关闭所有图形窗口,清除工作空间所有变量,清空命令行
stu=cell(2); %cell函数建立2×2细胞数组
stu{1,1}={‘LiMing‘,‘WangHong‘};
stu{1,2}={‘20120101‘,‘20120102‘};
stu{2,1}={‘f‘,‘m‘};
stu{2,2}={20,19};
stu;
cellplot(stu) %显示细胞数组结构图
由代码编译出的student细胞数组结构图如下图所示:

(2)细胞数组类型的操作
| 函数 | 说明 |
| cell2struct(cellArray,fields,dim) | 将细胞数组转换成结构数组 |
| iscell(c) | 判断指定数组是否是细胞数组 |
| struct2cell(s) | 将结构数组转换成细胞数组 |
| mat2cell(A,m,n) | 将矩阵拆分成细胞数组矩阵 |
| cell2mat(c) | 将细胞数组合并成矩阵 |
| num2cell(A) | 将数值数组转换成细胞数组 |
| celldisp(c) | 显示细胞数组内容 |
| cellplot(c) | 显示细胞数组结构图 |
原文:http://www.cnblogs.com/sharilove/p/sharilove_digital_image_processing_003.html