三十四周一天是几个月(周一分享三十四)

Matlab入门学习

Getting started with Matlab

三十四周一天是几个月(周一分享三十四)(1)

分享兴趣,传播快乐,

增长见闻,留下美好。

亲爱的您,

这里是LearingYard学苑!

今天小编为大家带来Matlab入门学习。

欢迎您的用心访问!

本期推文阅读时长大约5分钟,请您耐心阅读。

Share interests, spread happiness,

increase knowledge, and leave beauty behind.

Dear you,

this is LearningYard Academy!

Today,the editor brings you Matlab introductory learning.

Welcome your visit!

The reading time of this tweet is about 5 minutes, please read it with patience.

今天小编为大家介绍元胞数组的索引、修改、添加、删除、连接、转换。

Today, I will introduce you to the indexing, modification, addition, deletion, connection, and transformation of cell arrays.

索引

Index

可以用大括号和小括号对元胞数组进行索引,下面来看示例,可以看到使用小括号进行索引是对整个元胞数组中元胞的整体进行索引,元素仍然是cell类型,使用大括号可以索引到元胞数组内元素的具体内容,是3*3的魔方矩阵,有9个数字。二级索引先用大括号再用小括号,可以看到第一行第三个元素是3*3的魔方矩阵,魔方矩阵的第二行第二列是5。

You can use curly brackets and parentheses to index cell arrays. Let’s look at the example below. You can see that indexing with parentheses is to index the entire cell array in the entire cell array. The element is still of type cell, and curly brackets are used. The specific content of the elements in the cell array that can be indexed is a 3*3 magic Square matrix with 9 numbers. The secondary index uses curly brackets and then parentheses. You can see that the third element in the first row is a 3*3 Rubik's cube matrix, and the second row and second column of the Rubik's cube matrix is 5.

三十四周一天是几个月(周一分享三十四)(2)

三十四周一天是几个月(周一分享三十四)(3)

三十四周一天是几个月(周一分享三十四)(4)

三十四周一天是几个月(周一分享三十四)(5)

三十四周一天是几个月(周一分享三十四)(6)

三十四周一天是几个月(周一分享三十四)(7)

三十四周一天是几个月(周一分享三十四)(8)

三十四周一天是几个月(周一分享三十四)(9)

修改

Revise

通过给需要修改的元胞赋值来进行修改,两种方法可以进行修改。下面来看一个示例,把元胞数组b的第一行第一列的1改为100。如下图所示,使用小括号索引,100外加大括号,使用大括号索引,直接写100。

The modification is made by assigning a value to the cell to be modified. There are two methods for modification. Let's see an example of changing the 1 in the first row and first column of cell array b to 100. As shown in the figure below, use parentheses for indexing, 100 for curly brackets, use curly brackets for indexing, and write 100 directly.

三十四周一天是几个月(周一分享三十四)(10)

三十四周一天是几个月(周一分享三十四)(11)

三十四周一天是几个月(周一分享三十四)(12)

三十四周一天是几个月(周一分享三十四)(13)

添加

Add to

b是2行3列的元胞数组,此时索引元胞数组b的第三行第四列,并赋值为8,可以看到此时元胞数组b扩展为3行4列,其他地方是用默认的空矩阵进行填充。

b is a cell array with 2 rows and 3 columns. At this time, index the third row and fourth column of the cell array b and assign the value to 8. It can be seen that the cell array b is expanded to 3 rows and 4 columns at this time, and the other places are Fill with the default empty matrix.

三十四周一天是几个月(周一分享三十四)(14)

三十四周一天是几个月(周一分享三十四)(15)

删除

Delete

元胞数组的删除主要是通过把需要删除的元胞赋值为空。利用大括号可以删除元胞数组元胞内的具体内容。大括号索引具体内容,设置为空,元素内容会变成一个空矩阵。小括号可以整行整列的删除,但不能删除具体的一个元胞。

The deletion of a cell array is mainly by assigning empty cells to be deleted. Use curly braces to delete specific contents of a cell array cell. The curly brackets index the specific content. If set to empty, the element content will become an empty matrix. Parentheses can delete the entire row and column, but cannot delete a specific cell.

三十四周一天是几个月(周一分享三十四)(16)

三十四周一天是几个月(周一分享三十四)(17)

三十四周一天是几个月(周一分享三十四)(18)

三十四周一天是几个月(周一分享三十四)(19)

连接

Connect

方括号进行连接,中间加分号是垂直连接,但是列数不同无法连接,中间加逗号是水平连接。把元胞数组打开再进行重排,结果是1*4的元胞数组。大括号进行连接,列数不同也可垂直连接,结果是1*2的元胞数组。

Square brackets are used for connection, and a semicolon in the middle is a vertical connection, but the number of columns cannot be connected, and a comma in the middle is a horizontal connection. Opening and rearranging the cell array results in a 1*4 cell array. The braces are used to connect, and the number of columns can also be connected vertically. The result is a 1*2 cell array.

三十四周一天是几个月(周一分享三十四)(20)

三十四周一天是几个月(周一分享三十四)(21)

三十四周一天是几个月(周一分享三十四)(22)

三十四周一天是几个月(周一分享三十四)(23)

三十四周一天是几个月(周一分享三十四)(24)

三十四周一天是几个月(周一分享三十四)(25)

三十四周一天是几个月(周一分享三十四)(26)

三十四周一天是几个月(周一分享三十四)(27)

转换

Convert

cell2mat()元胞数组转换为普通矩阵。每个元素是相同的类型并且有相同的大小,这样的元胞数组才可以进行转换,转换之后的格式遵循原来的格式。把其他类型转换成元胞数组的时候要指定行数和列数。元胞数组与数值类型的相互转换通过num2cell()函数实现,具体示例如下。

cell2mat() converts a cell array to an ordinary matrix. Each element is the same type and has the same size, so that the cell array can be converted, and the converted format follows the original format. Specify the number of rows and columns when converting other types to cell arrays. The conversion between cell arrays and numeric types is implemented by the num2cell() function. The specific example is as follows.

三十四周一天是几个月(周一分享三十四)(28)

三十四周一天是几个月(周一分享三十四)(29)

三十四周一天是几个月(周一分享三十四)(30)

三十四周一天是几个月(周一分享三十四)(31)

三十四周一天是几个月(周一分享三十四)(32)

三十四周一天是几个月(周一分享三十四)(33)

三十四周一天是几个月(周一分享三十四)(34)

三十四周一天是几个月(周一分享三十四)(35)

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's it for today's sharing.

If you have a unique idea about today’s article,

welcome to leave us a message,

let us meet tomorrow.

I wish you a happy day today!

参考资料:谷歌翻译、百度、哔哩哔哩

本文由LearningYard学苑原创,如有侵权请在后台留言!

文字|Zheng

排版|Zheng

审核|任务达人

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页