Matlab中的Cell和logical

来源:互联网 发布:淘宝电吉他的价格 编辑:程序博客网 时间:2024/05/20 07:14

(1)Matlab中什么是Cell

Cells可以容纳各种数据类型

按照Matlab的文档解释:

What Is a Cell Array?
A cell array is a collection of containers called cells in which you can store different types of data. 


Cells的操作:



(2)Matlab中什么是logical

logical是布尔变量,可以是一个标量,也可以是一个向量或者是矩阵。可以用作下标。

在帮助文档中给出了一个例子:

A = [1 2 3; 4 5 6; 7 8 9]

要想取出对角元素,可以用diag(A),也可以借助下标。

构建一个logical矩阵,或者说是下标矩阵 logical(eye(3))

即:[1 0 0;

0 10;

0 01;]

A(logical(eye(3))的意思是取出下标为真的元素:

最终返回:[1;5;9];