研读分享一看就会的图文教程Matlb(2)
分享兴趣、传播快乐、增长见闻、留下美好,大家好,这里是LearningYard学苑,今天小编为大家带来文章:一看就会的图文教程-Matlb(2)。
今日内容简介:
在之前的文章中,已经介绍过matlab软件的打开界面和一些实用指南,也介绍过用matlab绘制简单的二维图与三维图的方法。今天,我们着重来学习matlab中关于矩阵计算和代码编写中循环语句的一些命令格式。 01 Matlab中关于矩阵的那些事
Matlab以"矩阵"闻名,下面我们通过一些简单的案例理解这些常用的矩阵命令。
具体的案例为:
02条件语句
if 条件语句相对比较简单,一般地,在下面这个条件语句中。如果满足条件1,则执行命令1(statements1)后结束。如果不满足 expression1也不满足 expression2,则执行statements3。
一般的if结构为:
if expression1
statements1
elseif expression2
statements2
else
statements3
end
另外,在有多个if结构的条件语句中。MATLAB 翻译器经常把把已知的 end 语句和它最近的 if 语句联合在一起。
案例展示:
03循环结构
对于一些简单的命令,既可以用if结构实现,也可以用循环结构。
循环(loop)是一种 MATLAB 结构,它允许我们多次执行一系列的语句。循环结构有两种基本形式:while 循环和 for 循环。两者之间的最大不同在于代码的重复是如何控制的。在while 循环中,代码的重复的次数是不能确定的,只要满足用户定义的条件,重复就进行下去。相对地,在 for 循环中,代码的重复次数是确定的,在循环开始之前,我们就知道代码重复的次数了。
如果 expression 的值非零(true),程序将执行代码块(code block),然后返回到 while 语句执行。如果 expression 的值仍然非零,那么程序将会再次执行代码。直到 expression 的值变为 0,这个重复过程结束。当程序执行到 while 语句且 expression 的值为 0 之后,程序将会执行 end 后面的第一个语句。
其中 index 是循环变量(就是我们所熟知的循环指数),exp 是循环控制表达式。变量 index读取的是数组 expr 的行数,然后程序执行循环体(loopbody),所以 expr 有多少列,循环体就循环多少次。
在 for 和 end 之前的语句我们称之为循环体。在 for 循环运转的过程中,它将被重复的执行。
For 循环结构函数如下:
1.在 for 循环开始之时,MATLAB 产生了控制表达式
2.第一次进入循环,程序把表达式的第一列赋值于循环变量 index,然后执行循环体内
的语句。
3.在循环体的语句被执行后,程序把表达式的下一列赋值于循环变量 index,程序将再
一次执行循环体语句。
4.只要在控制表达式中还有剩余的列,步骤 3 将会一遍一遍地重复执行。
英文学习:
Today"s content introduction:
In the previous article, I have introduced the opening interface of the matlab software and some practical guides, and also introduced the method of drawing simple two-dimensional and three-dimensional diagrams with matlab. Today, we will focus on learning some command formats for matrix calculations and loop statements in code writing in matlab.
Those things about matrices in Matlab
Matlab is famous for "matrix", let"s understand these commonly used matrix commands through some simple cases.
Conditional statements
The if conditional statement is relatively simple, generally, in the following conditional statement. If condition 1 is met, then the execution of command 1 (statements1) ends. If neither expression1 nor expression2 is satisfied, statements3 are executed.
In addition, in conditional statements with multiple if structures. The MATLAB translator often combines the known end statement with its nearest if statement.
For some simple commands, you can either use an if structure or a loop structure.
A loop is a MATLAB structure that allows us to execute a series of statements multiple times. There are two basic forms of loop structure: while loop and for loop. The biggest difference between the two is how the code duplication is controlled. In the while loop, the number of code repetitions cannot be determined. As long as the user-defined conditions are met, the repetition will continue. In contrast, in a for loop, the number of code repetitions is definite. Before the loop starts, we know the number of code repetitions.
If the value of expression is non-zero (true), the program will execute the code block and then return to the while statement execution. If the value of expression is still non-zero, the program will execute the code again. Until the value of expression becomes 0, this repeated process ends. When the program executes to the while statement and the value of expression is 0, the program will execute the first statement after end.
Among them, index is the loop variable (the loop index as we know it), and exp is the loop control expression. The variable index reads the number of rows in the array expr, and then the program executes the loop body, so the loop body will loop as many times as there are columns in expr.
The statements before for and end are called loop bodies. While the for loop is running, it will be executed repeatedly. For loop structure functions are as follows:
1. At the beginning of the for loop, MATLAB generates the control expression
2. When entering the loop for the first time, the program assigns the first column of the expression to the loop variable index, and then executes the loop body
Statement.
3. After the statement in the loop body is executed, the program assigns the next column of the expression to the loop variable index, and the program will
Execute the loop body statement once.
4. As long as there are remaining columns in the control expression, step 3 will be repeated over and over again.
由于篇幅有限,今天的分享就到这里啦!
感兴趣的同学可以留言与小编交流,
咱们下周见!
参考资料:周一帆师兄的学习文档。
英文翻译:Google翻译。
本文由LearningYard学苑整理并发出,如有侵权,请联系删除!
2021最后一个季度,最重要的事只有一件易经大师曾仕强,几年前在一次讲座中,说过一段话现在地球能量不平衡。天气一冷一热,一批人不见了。一冷一热,又一批人不见了。所以,人多的地方不可以去。因为今后都是一群一群地收。他没办法
中国台湾省小知识1。方便面和珍珠奶茶都是台湾人发明的2。台湾人民主要出行工具是摩托车3。台湾的空气质量并不太好,特别是台南4。台北到高雄的高铁造了7年多,列车采用用日本系统,机电系统采用欧洲规格,
中国社科院房价收入比已达9。31超临界点对经济贡献由正转负在中国经济快速发展的时期,房地产及其相关行业如火如荼发展。根据公开资料显示,房地产对经济的直接贡献,这些年每年至少保持在5以上。民间机构有做过测算,加上房地产关联的数百个行业,对G
三四线城市房价为啥贵?相关部门不让降开发商不想降一个地方的房价不仅仅受市场的影响,也受政策的影响。纵观全国房地产市场,小涨小降都是正常状态,但是大幅度的房价下降并不多见。一个是环京区域,由于受政策影响,燕郊香河等地房价下降明显。
90后广漂躲过了高房价,却躲不过高房租在一线城市中,广州不仅房价最良心,而且还拥有一个最包容最多元的租房市场。这是一个很容易让人找到落足点的城市,深得广漂心。然而,近期管家的涨租通知,击碎了90后广漂小苏的都市丽人梦。
好男人!TVB小生曝老婆管财政没信用卡电子钱包只有500元额度圈中其实有不少好男人,他们大多数都很顾家,而且更有人将家里的财政大权交给太太。其中有一位近日刚成为三胎爸爸的TVB小生出席活动就自曝财政由老婆管,而自己则一直都没信用卡,电子钱包也
台北故宫3宝,密码藏千年,技工破解中国画的蒙娜丽莎郭熙早春图。图故宫提供提到台北的故宫三宝,人们想到的往往是翠玉白菜肉形石与毛公鼎。然而对艺术史学者来说,真正的台北故宫三宝应该是北宋三件山水画范宽的溪山行旅郭熙的早春图与李唐的万壑
历经32年,台北的市井记忆,很魔幻很久很久以前,当韩流还未正式入侵内地之前,在我们这代人的童年记忆中,台剧占有着非常重要的地位,各种玄幻童话都市爱情都市怪谈。。败犬女王中,大龄未婚的败犬女王,也算是现代女性题材的初
最牛浙江人(近现代浙江名人)鲁迅蔡元培周作人郁达夫茅盾章太炎蒋梦麟巴金(原籍)钱玄同王国维罗家伦龚自珍杨贤江梁实秋陈望道李叔同(弘一大师)钱理群徐志摩俞平伯沈钧儒周建人马述伦陈述通胡愈之经叔平韩启德蒋正华秋瑾
东京奥运会,个人建议中国不参与。为国争光的前提是保证安全今天报道说是东京奥运会出现了参加比赛的工作人员有疫情,日本疫情本来就非常严重,国家管理也不是那么妥善。前两天还报道有日本人脱掉口罩硬要跟中国运动员合影,我都怀疑那家伙是故意的。作为
错换直播泡汤,庭外人群聚集一直牵动人心的错换人生28年案,今天终于又一次开庭了。庭审的地方被临时更换到一处偏僻的法院,但这并不能阻挡网友的热情,从新闻报道可以看出,庭外有数百人聚集在那里。今天开封的天气并不