This tweet will introduce the cellular array of Matlab introductory learning (2) from content summary, mind map, and introductory learning, of which introductory learning is divided into knowledge introduction and software practice.
Cell arrays are a special data type of Matlab, which treats cell arrays as an all-encompassing universal matrix, or generalized matrix. The elements that make up the cell array are constants or constants of any data type, each element also has a different size and memory footprint, and the content of each element is completely different, so the elements of the cell array are called cells. There are three ways to create a cell array: direct assignment method, using the function cell "( )", and using "{ }" to directly create all cells of the cell array.
(二)软件实操(Software hands-on)
1. 采用直接赋值法进行cell数组的创建
1. Use the direct assignment method to create a cell array
(1)内容索引法
(1) Content indexing method
代码如下图所示:
The code is shown in the following figure:
运行结果如下图所示:
The running result is shown in the following figure:
(2)单元索引法
(2) Unit index method
代码如下图所示:
The code is shown in the following figure:
运行结果如下图所示:
(3)利用函数cell“( )”进行cell数组的创建
2. Use the function cell "( )" to create a cell array
Using the function cell(), you can create an array of cells and specify its size. However, this is only a predefined cell array, and then the assignment method needs to be used to initialize the assignment of each cell cell, which is the same as the direct assignment method.
代码如下图所示:
The code is shown in the following figure:
运行结果如下图所示:
(4)利用“{ }”进行cell数组的创建
3. Create a cell array using "{ }"
代码如下图所示:
The code is shown in the following figure:
运行结果如下图所示:
(5)cell数组的常用相关操作
4. Common related operations for cell arrays
(1)提取数组具体元素
(1) Extract the specific elements of the array
此处提取了相应数组的第一行第二列的内容,代码如下图所示:
Here the inside of the first row and second column of the corresponding array is extracted, the code is shown in the following figure:
运行结果如下图所示:
The running result is shown in the following figure:
We can use the function cell2mat() to convert an array of cells to a normal matrix. Each element in the cell array is of the same type and has the same size before it can be converted, and the converted format follows the original format. mat2cell() converts a matrix of values into an array of cells. num2cell() converts an array of values into an array of cells. Here, the cell array is converted to a normal matrix.
Previously we defined C as a cell array with 2 rows and 2 columns, at this time we add the 3rd row and 3rd column of the index cell array b, and assign the value to 17, we can see that at this time the cell array C is expanded to 3 rows and 3 columns, and the rest of the place is filled with the default empty matrix.
代码如下图所示:
The code is shown in the following figure:
运行结果如下图所示:
(4)修改元胞数组
(4) Modify the cell array
通过给需要修改的元胞赋值来进行修改,代码如下图所示:
Modify it by assigning values to the cells that need to be modified, the code is shown in the following figure:
运行结果如下图所示:
The running result is shown in the following figure:
First, create a number with the same dimension as the previous cell array, and then connect, where the cell array E is the horizontal connection of the cell array C and D, and F is the vertical connection of the cell array C and D.