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

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

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

#元胞数组基本概念:元胞数组是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学苑原创,如有侵权请联系删除。

    推荐阅读
  • 5g技术会朝哪个方向发展(深度研究5G将会带来什么)

    5G网络作为第五代移动通信网络,5G网络的主要目标是让终端用户始终处于联网状态。5G网络将是4G网络的真正升级版,它的基本要求并不同于无线网络。而未来5G的传输速度讲达到10Gbps。所以5G的诞生应该是对于万物互联的一种效率再提升的节奏。

  • 新东风日产轩逸智享版有导航吗(东风日产轩逸原装导航)

    新款Sylphy不仅车身长度增加了50毫米,还重新设计了前进气格栅,酷似新一代天蝎座。此外,全新Sylphy车型配备自动开闭大灯,确保消费者在驾驶时的安全。值得一提的是,全新Sylphy的高配车型还增加了倒车影像,确保消费者停车时的安全。作为一款家庭经济型轿车,新款Sylphy对轮胎的要求非常高。全新Sylphy的车门内衬采用皮革和木纹装饰,不仅提升了整车的豪华感,还减轻了驾驶员长途驾驶时的疲劳感。新款Sylphy的驾驶员座椅车窗由一个按钮控制。

  • 衣服上的墨水迹怎么洗掉(怎么洗掉衣服上的墨水渍)

    之后再加入少量的中性洗涤剂搓洗,可彻底去除墨水渍,连印记也没有。

  • 阿能组什么词(阿字的组词介绍)

    接下来我们就一起去了解一下吧!阿能组什么词阿字的组词有阿爸、阿姨、阿谀、阿胶、阿片、阿斗、阿婆、阿公、阿訇、阿嚏、阿附、阿门、松阿、阿黎等。用在排行、小名或姓的前面,有亲昵的意味:阿大。阿字的笔画笔顺是横折折折钩/横撇弯钩,竖,横,竖,横折,横,竖钩。

  • 上海图书馆读书日(走进交大图书馆)

    1917年3月,学校面向师生校友及社会各界印发《南洋公学二十周年纪念图书馆募捐启》,不到一年的时间,社会各界捐款和交通部拨款合计8.5万元。即将落成的图书馆南楼1995年经中央同意,具有百年历史的西安交通大学图书馆命名为“钱学森图书馆”。1996年4月8日,西安交大百年校庆期间举办“钱学森图书馆”命名仪式。至此,三校区图书馆并行局面形成,总建筑面积达43794平方米,阅览座位3604席。

  • biubiu加速器商城(biubiu加速器积分可兑奖)

    近日,可免费支持海内外近3000款手游加速的biubiu加速器上线积分商城,玩家可通过积分兑换精美游戏周边,首期豪礼8款绝地求生精美周边正在等待认领。biubiu加速器是一款手游加速器,不仅有效解决手机游戏游玩过程中的高延迟丢包问题,而且至今免费。加速器现已支持3000款手游,海外新上线的手游,biubiu会第一时间更新,biubiu游戏库囊括各种类型游戏,热门游戏皆一应俱全。之前的版本中,biubiu已添加了积分功能。

  • 生活小百科知识大全儿童(生活小百科)

    牙膏涂抹,牙膏含有二氧化硅,温度比较低,可以抑制被辣椒辣到后皮肤上的灼热感,辅助消除红肿。涂清凉油,清凉油有清凉散热、止痒止痛的功效,在患处红肿、没有破皮的情况下,可涂抹清凉油缓解。同时,蔬菜中的很多种营养素也被破坏了。正确的炒菜方式是热锅凉油,先把锅烧热,然后加入油,稍微等油热了但尚未冒烟时再放食材,这样会更健康。

  • 西安芙蓉园水幕电影现在能看么 西安芙蓉园水幕电影几点开始

    西安大唐芙蓉园的水幕电影现在是可以看的大唐芙蓉园演出时间表

  • 怎么改变电脑磁盘分区位置(改变电脑磁盘分区位置方法)

    怎么改变电脑磁盘分区位置?作一个U盘winpe制作完成后,在官网查询U盘启动快捷键,我来为大家科普一下关于怎么改变电脑磁盘分区位置?插入U盘winpe后,重启电脑,在电脑开机画面出现时,迅速按下U盘启动快捷键,进入优先启动项设置页面,选中U盘选项并。进入winpe主菜单后,选择Win10X64PE,按进入winpe桌面。重新分区时,请耐心等待,分区完毕后会有小弹窗出现,点击即可,之后回到分区管理页面,就可以看到重新分区的磁盘分区图。