MATLAB入门学习——元胞组数1

分享兴趣,传播快乐,
增长见闻,留下美好!
亲爱的您,这里是LearningYard学苑。
今天小编为大家带来的主题是MATLAB学习——元胞数组,
欢迎您的用心访问,
本期推文阅读时长大约5分钟,
请您耐心阅读。
Share interest, spread happiness,
Increase knowledge and leave good news!
Dear you, this is LearningYard Academy.
The topic that Xiaobian brings to you today is MATLAB learning - cell array,
Welcome your visit with heart,
This tweet is about 5 minutes long to read.
Please read with patience.
大家好,本周小编为大家带来的是MATLAB的元胞数组章节,首先带大姐了解一下基本概念:
元胞数组是MATLAB的一种特殊数据类型,可以将元胞数组看作一种无所不包的通用矩阵,或者叫做广义矩阵。组成元胞数组的元素可以是任何一种数据类型的常数或者常量,每一个元素也可以具有不同的尺寸和内存占用空间,每一个元素的内容也可以完全不同,所以元胞数组的元素叫做元胞(cell)。
Hello everyone, this week Xiaobian brings you the cell array chapter of MATLAB. First of all, I will take the elder sister to understand the basic concepts:
A cell array is a special data type of MATLAB, which can be regarded as an all-encompassing general matrix, or a generalized matrix. The elements that make up a cell array can be constants or constants of any data type, each element can also have a different size and memory footprint, and the content of each element can also be completely different, so the elements of the cell array are called elements. cell.
适用范围
假设自己需要在MATLAB中保存4组信息,它们分别是:
【实数】6;
【向量】[1 2 3];
【文本】LearningYard;
【矩阵】magic(4)。
我们可以用MATLAB将他们保存在2×2的cell元胞数组中,将其当作一个储存信息的“储物柜”。


代码编写
代码:
Number=6
Array=[1 2 3]
String='LearningYard';
Matrix=magic(4);
cell={Number,Array;String,Matrix}
运行可以得到:


相关指令
1.假设需要提取上述2×2的cell数组中的字符串"LearningYard",我们可以通过类似提取矩阵元素的操作指令进行:
cell{2,1}或cell{2}。
注:这里需要用到大括号。
2.元胞数组的转化:
cell2mat 将元胞数组转变成为普通的矩阵
mat2cell 将数值矩阵转变成为元胞数组
num2cell 将数值数组转变成为元胞数组
1. Assuming that the string "LearningYard" in the above 2×2 cell array needs to be extracted, we can do it through an operation instruction similar to extracting matrix elements:
cell{2,1} or cell{2}.
Note: Braces are required here.
2. Conversion of cell array:
cell2mat converts a cell array to a normal matrix
mat2cell converts a numeric matrix to a cell array
num2cell converts a numeric array to a cell array

今天的分享就到这里了。
如果您对今天的文章有独特的想法,
欢迎给我们留言,让我们相约明天,
祝您今天过得开心快乐!
That's it for today's sharing.
If you have a unique idea for today's article,
Welcome to leave us a message, let us meet tomorrow,
I wish you a great day today!
