高考考试网
当前位置: 首页 高考资讯

matlab常用操作总结(MATLAB学习之进阶指令)

时间:2023-06-01 作者: 小编 阅读量: 3 栏目名: 高考资讯

#元胞数组基本概念:元胞数组是MATLAB的一种特殊数据类型,将元胞数组看作一种无所不包的通用矩阵,或者叫做广义矩阵。我们用MATLAB将他们保存在2×2的cell元胞数组中,将其当作一个储存信息的“储物柜”。假设需要提取上述2×2的cell数组中的字符串"LearningYard",我们通过类似提取矩阵元素的操作指令进行:cell{2,1}或cell{2}。然后需要注意的是需要把矩阵现用空集进行表示,否则在for循环中无法识别Test_Matrix。

分享兴趣,传播快乐,

增长见闻,留下美好!

亲爱的您,这里是LearningYard学苑。

之前小编带领大家学习了一些MATLAB的基础操作,忘记了的同学赶快补课。

今天小编给大家带来的是一些进阶学习,一起来看看吧!

#元胞数组

基本概念:元胞数组是MATLAB的一种特殊数据类型,将元胞数组看作一种无所不包的通用矩阵,或者叫做广义矩阵。组成元胞数组的元素是任何一种数据类型的常数或者常量,每一个元素也具有不同的尺寸和内存占用空间,每一个元素的内容也完全不同,所以元胞数组的元素叫做元胞(cell)。

适用情境:假设自己需要在MATLAB中保存4组信息,它们分别是:

【实数】6;

【向量】[1 2 3];

【文本】LearningYard;

【矩阵】magic(4)。

我们用MATLAB将他们保存在2×2的cell元胞数组中,将其当作一个储存信息的“储物柜”。

代码编写:新建脚本,采用大括号{ }进行cell数组的创建:

运行后,命令行窗口如下显示:

除此之外,还可通过指令“celldisp”来显示所有元胞的内容。

假设需要提取上述2×2的cell数组中的字符串"LearningYard",我们通过类似提取矩阵元素的操作指令进行:

cell{2,1}或cell{2}。

注:这里需要用到大括号。

那么怎么将元胞数组转化为其他形式呢?

cell2mat 将元胞数组转变成为普通的矩阵

mat2cell 将数值矩阵转变成为元胞数组

num2cell 将数值数组转变成为元胞数组

#循环覆盖值累积

在学习VIKOR算法过程中,我们需要确定群体效用值和个体遗憾值的时候用到了“end 1”和矩阵分行操作,假如在该步骤将“end 1”删掉,那么结果会发生怎样的改变呢?

删掉“end 1”后的代码变化后的结果见下图,截图还没有截全,但我们能清楚地看到Best_value和Worst_value的数值随着语句的循环一直在发生更替,而且它们的属性变成了1×1的double形式,不再是向量了。

使用“end 1”有效避免循环语句中数值覆盖的情况,我们来看一下“end 1”具体的工作流程:

Best_value =

1

Worst_value =

0

Best_value =

1 1

Worst_value =

0 0

Best_value =

1 1 1

Worst_value =

0 0 0

Best_value =

1 1 1 1

Worst_value =

0 0 0 0

它会把数值不断累积,使其变成一个向量。但需要注意的是Best_value和Worst_value这两个变量必须先将其定义为一个空集“[ ]”,否则在end 1步骤中会报错。

#行向量转化为矩阵

通过(end 1)指令编码出来的结果都是行向量的形式,如果要将其转化为矩阵,我们可以将矩阵理解为多个规格相同的行向量进行累积,用代码表示为:

[row1;row2;row3;row4]

将行向量用分号分开,它们就组成了矩阵。

以Test_Vector=[1,2,3,4,5,6,7,8,9]为例,将其变为如下形式的3×3矩阵。

方法很简单,代码表示如下:

Test_Vector=[1,2,3,4,5,6,7,8,9]

Size_Test_Vector=size(Test_Vector);

Test_Vector_Column=Size_Test_Vector(2);

Test_Matrix=[ ];

for i=[1:3:Test_Vector_Column]

Test_Matrix_Change=Test_Vector(i:i 2);

Test_Matrix=[Test_Matrix;Test_Matrix_Change];

end

display(Test_Matrix)

首先定义行向量的规格尺寸,以方便对其分行。然后需要注意的是需要把矩阵现用空集进行表示,否则在for循环中无法识别Test_Matrix。最后在for循环内用change的变量对行向量的内容进行截取,用[Test_Matrix;Test_Matrix_Change]的方式重复对Test_Matrix进行赋值,使其变成矩阵的形式。最终得到的结果如下:

#英文学习

1. Cell array

Basic concept: Cell array is a special data type of MATLAB. Cell array is regarded as a kind of all-encompassing general matrix, or generalized matrix. The elements that make up a cell array are constants or constants of any data type. Each element also has a different size and memory footprint. The content of each element is also completely different. Therefore, the elements of the cell array are called cell (cell ).

Applicable situation:

Suppose you need to save 4 sets of information in MATLAB. They are:

We use MATLAB to store them in a 2×2 cell array, treating it as a "storage cabinet" for storing information.

Code writing: create a new script, use braces {} to create a cell array:

After running, the command line window is displayed as follows:

In addition, the content of all cells can also be displayed through the command "celldisp".

Suppose we need to extract the string "LearningYard" in the above 2×2 cell array, we use similar operation instructions to extract matrix elements:

cell{2,1} or cell{2}.

Note: Braces are needed here.

So how to convert the cell array into other forms?

cell2mat transforms a cell array into a normal matrix

mat2cell transforms a numeric matrix into a cell array

num2cell turns a numeric array into a cell array

2. Cycle coverage value accumulation

In the process of learning the VIKOR algorithm, we need to use the "end 1" and matrix branch operations when determining the group utility value and the individual regret value. If "end 1" is deleted in this step, what will happen to the result? Change?

Delete the code after "end 1"

The result of the change is shown in the figure below. The screenshot has not been truncated yet, but we can clearly see that the values of Best_value and Worst_value are constantly changing as the sentence loops, and their attributes have become 1×1 doubles. It's not a vector anymore.

Use "end 1" to effectively avoid the value coverage in the loop statement. Let's take a look at the specific workflow of "end 1":

It will accumulate the value continuously, making it a vector. But it should be noted that the two variables Best_value and Worst_value must first be defined as an empty set "[ ]", otherwise an error will be reported in the end 1 step.

3. Convert row vector to matrix

The result encoded by the (end 1) instruction is in the form of a row vector. If you want to convert it into a matrix, you need to use the following techniques.

We can understand the matrix as the accumulation of multiple row vectors of the same specification, expressed in code as:

Separate the row vectors with semicolons and they form a matrix.

Take Test_Vector=[1,2,3,4,5,6,7,8,9] as an example, and change it into a 3×3 matrix in the following form.

The method is very simple, the code is as follows:

First define the size of the row vector to facilitate its branching. Then it should be noted that the current matrix needs to be represented by an empty set, otherwise the Test_Matrix cannot be recognized in the for loop. Finally, in the for loop, the content of the row vector is intercepted with the variable of change, and the Test_Matrix is repeatedly assigned by the method of [Test_Matrix;Test_Matrix_Change] to make it into the form of a matrix. The final result is as follows

参考资料:谷歌翻译、《MATLAB入门教程》

本文由LearningYard学苑原创,如有侵权请联系删除。

    推荐阅读
  • 常用字30个(常用字范式之八十一)

    常用字范式之八十一常用字范式之八十一、九画之一:奏:虽如草芥亦恭敬双手奉上犹荐发其陈奉而进之以尽其义者是奏字之范式春:《说文解字》:“春,推也从艸、从日,艸春時生也;屯声”(艸:参见四画之八“艸”)(日:参见四画之六“。

  • 郑州高新区餐饮停业公告(15楼财经食品柜里有老鼠)

    目前,属地市场监管部门已对此事立案调查,并责令商户立即停业整顿。检查期间,执法人员没有发现老鼠踪迹。不过,市场监管部门还是责令商户立即停业整顿,聘请第三方开展灭鼠行动,排除卫生安全隐患。目前该公司对外投资企业共45家,开设紫燕百味鸡全国连锁店超4000家。今年7月,上海紫燕食品股份有限公司提交IPO招股书。但是,失去了对终端管理的直接把控,紫燕食品的食安问题频发的现状仍未能得到根本上的解决。

  • 当上公务员是种什么感觉(当公务员真的这么好吗)

    没错,作为一个过来人,必须语重心长的告诉你,当公务员对绝大部分人来说都是一个非常好的选择!当然,公务员不是100%适合每一个人,它也有不是那么好的地方。对于很多很多普通的人来说,能够有一份“工作稳定、收入稳定、未来稳定”的工作是一个最靠谱的选择,而公务员这份工作则是答案之一。虽然不一定是最好最有的选择,但肯定是一个不会犯错的选择。

  • acd看图软件安装教程(可以直接看ps的看图软件分享)

    今天小编给大家推荐一款每个造价人都必须使用的一款实用软件–CAD快速看图,打开速度远远甩了效率低下的CAD几十条街,而且版本免安装,下载好压缩包后,解压后直接打开即可。CAD快速看图除了可以进行查看外,另外还可以对内容进行标注测量,包括对齐,线性,面积、弧长测量,而且可以对设计图纸进行文字查找,以及对图纸进行图层管理等功能(附图)。

  • 马桶安装方法(该怎么操作呢)

    马桶安装方法检查排污管道与地面水平度,必须查看一下排污管道内是不是有泥沙、废纸等杂物的堵塞,同时也要检查清楚马桶所安装的位置地面前后左右是否水平,不平需要找平。固定马桶,先把马桶与地面排污口的十字线对准,确保水平安装马桶的同时再用力压紧密封圈,下一步就是安装地脚的螺丝与装饰帽固定马桶。在保证自来水的清洁没问题,再进行角阀与连接软管的安装,接着把软管与安装的水箱配件进行水阀的连接。

  • 将心比心课文(将心比心原文)

    第三针果然成功了。那位护士终于长出了一口气,她连声说:阿姨,真对不起。我真希望她第一次扎针的.时候,也能得到患者的宽容和鼓励。听了母亲的话,我心里充满了温暖与幸福。是啊,如果我们在生活中能将心比心,就会对老人生出一份尊重,对孩子增加一份关爱,就会使人与人之间多一些宽容与理解。

  • 怎么降低汽车尾气HC(汽车尾气不合格怎么处理)

    火花塞点火能量不足,不能把混合汽完全燃烧,导致尾气中HC含量超标,另外喷油嘴雾化不好,混合汽过浓,这些都会导致尾气不能通过,更换火花塞,清洗喷油嘴,就能解决问题。在检车前,使用燃油添加剂给爱车做一次清洗,可以有效减少尾气排放量,从而达到通过检测的目的,使用过的车主都说有效。更换更高标号汽油。清洗三元催化或更换三元催化。

  • 真的和田玉有哪些特征(顶级的和田玉应该具备)

    现在称之为的产地越来越多,广义上的概念让你对和田玉身世会更加的迷惑。那你真的知道什么样的和田玉才算是顶级货吗?老熟料的和田玉结构细腻致密,玉质感非常好!2》油油性足这是和田玉的灵魂指标,以前的文章里也多次提到了!如果一块和田玉油性很足,这块和田玉也不会差。5》皮和田玉的皮早就成了高贵的象征了!好的和田玉这五个特征不一定全都出现,出现3个特征以上就已经是难得的料子了!

  • 期待和期许分别是什么意思 期待的期什么意思

    语出明朝张敬修《文忠公行实》中而其学一本之躬行,根极理道,以此独深相期许。

  • 初学者瑜伽教程(初学者瑜伽教程说明)

    以下内容希望对你有帮助!第2种在保持腿部交叠状态的同时,两手臂可以向上伸直,向左向右摆动,这对于腰部的柔韧性锻炼特别好,而且下盘非常稳当。第3种采取坐式两腿伸直,两手臂也向前伸直,尽量把手臂向前伸,靠近脚尖部位,这个动作能有效的拉伸腿部和手臂部以及背部的经络。第4种两脚心相对,仍然是盘腿而坐,两手握住脚心动作能有效的拉伸大腿内部的韧带,而且动作难度很小,通常都能够做到。