Matlab-元胞数组的索引
2017-01-03 12:48
225 查看
%% 元胞数组的索引 C = {'one', 'two', 'three'; 1, 2, 3}; %% 1.Cell Indexing with Smooth Parentheses, () (操作数组本身) % 1. upperLeft = C(1:2,1:2) % 2. C(1,1:3) = {'first','second','third'} % 3.If cells in your array contain numeric data, you can convert the cells to a numeric array using the cell2mat function: % 将元胞数组中数值部分转化为矩阵 numericCells = C(2,1:3) numericVector = cell2mat(numericCells) %% 2.Content Indexing with Curly Braces, {} (操作数组里面的内容) % 1. last = C{2,3} % 2. C{2,3} = 300 % 3.access the contents of multiple cells C{1:2,1:2} [r1c1, r2c1, r1c2, r2c2] = C{1:2,1:2} % MATLAB? creates a comma-separated list. % Because each cell can contain a different type of data, % you cannot assign this list to a single variable. % However, you can assign the list to the same number of variables as cells. % MATLAB assigns to the variables in column order % 因为每一个元胞数组的内容不一样,所以不能将数据列在一个变量中,所以会按列的顺序分开列出所以的内容 % 4.当数据类型相同时,可以使用 [] 合并数据 nums = [C{2,:}] % * 数组可以使用 {} 合并 % 5.元胞数组的赋值操作 [r1c1, r2c1, r1c2, r2c2] = C{1:2,1:2} % 对内容赋值 rc = {C{1:2,1:2}} % 对内容操作 + 合并内容 rc = C(1:2,1:2) % 对元胞数组进行操作赋值 r1c1 = C{1:2,1:2} % 这种操作只能将第一个赋过去 % 6.结构体中产生的元胞数组 imname = dir(['C:\Users\ncf\Desktop\' '*.doc']);%读入文件夹下的 doc ,imname 为结构体 file_all = {imname.name}; % imname.name 产生元胞数组(因为每一个文档的名字长度不同) %% 3.多维数的操作 % 1. myNum = [1, 2, 3]; myCell = {'one', 'two'}; myStruct.Field1 = ones(3); myStruct.Field2 = 5*ones(5); C = {myNum, 100*myNum; myCell, myStruct}; C{1,2} C{1,1}(1,2) % 操作元胞中矩阵 C{2,1}{1,2} % 操作元胞中的元胞 C{2,2}.Field2(5,1) C{2,1}{2,2} = {pi, eps}; % 嵌入新的值, 对C{2,1}的元胞数组操作
相关文章推荐
- 解析在main函数之前调用函数以及对设计的作用详解
- C++如何调用matlab函数
- 详解Matlab中 sort 函数用法
- WPF调用Matlab函数的方法
- java和matlab画多边形闭合折线图示例讲解
- C#调用Matlab生成的dll方法的详细说明
- 简述Matlab中size()函数的用法
- 从java中调用matlab详细介绍
- Ubuntu 如何建立Matlab快捷方式
- 稀疏自动编码器 (Sparse Autoencoder)
- 详解Matlab中 sort 函数用法
- 简述Matlab中size()函数的用法
- VC++与Matlab混合编程的快速实现
- Matlab 矩阵运算
- matlab与opencv部分函数的对照
- matlab神经网络工具箱创建神经网络
- Matlab
- MATLAB 入门教程
- matlab函数_连通区域