Matlab学习小课堂总结(Summary of MATLAB Onramp)

Matlab学习小课堂总结(Summary of MATLAB Onramp)

学习完成Matlab基础之后来一篇小的基础总结很是必要, 一些基础的小例子可以帮助很好的理解(一例胜千言)

Basic syntax

ExampleDescription
x = piCreate variables with the equal sign (=). The left-side(x) is the variable name containing the value on the right-side(pi)
y = sin(-5)You can provide inputs to a function using parantheses.

Desktop management

FunctionExampleDescription
savesave data.matSave your current workspace to a MAT-file.
loadload data.matLoad the variables in a MAT-file to the Workspace.
clearclearClear all variables from the Workspace.
clcclcClear all text from the Command Window.
formatformat longChange how numeric output is displayed.

Array types

ExampleDescription
4scalar
[3 5]row vector
[1;3]column vector
[ 3 4 5;6 7 8]matrix

Evenly-spaced vectors

ExampleDescription
1:4Create a vector from 1 to 4, spaced by 1, using the colon( : ) operator.
1:0.5:4Create a vector from 1 to 4, spaced by 0.5.
linspace(1,10,5)Create a vector with 5 elements. The values are evenly spaced from 1 to 10.

Creating matrices

ExampleDescription
rand(2)Create a square matrix with 2 rows and 2 columns.
zeros(2,3)Create a rectangular matrix with 2 rows and 3 columns.

Indexing

ExampleDescription
A(end, 2)Access the element in the second column of the last row.
A(2, : )Access the entire second row.
A(1:3, : )Access all columns of the first three rows.
A(2) = 11Change the value of the second element an array to 11.

Array operations

ExampleDescriptions
[1 1; 1 1]*[2 2;2 2] --> ans = 4 4 4 4 \begin{matrix} 4& 4 \\ 4& 4 \\ \end{matrix} 4444Perform matrix multiplication
[1 1; 1 1].*[2 2;2 2] --> ans = 2 2 2 2 \begin{matrix} 2& 2 \\ 2& 2 \\ \end{matrix} 2222Perform element-wise multiplication.

Multiple outputs

ExampleDescriptions
[xrow, xcol] = size(x)Save the number of rows and columns in x to two different variables.
[xMax, idx] = max(x)Calculate the maximum value of x and its corresponding index value.

Documentation

ExampleDescription
doc randiOpen the documentation page for the randi function

Plotting

ExampleDescription
plot(x, y, “ro-”, “LineWidth”, 5)Plot a red ® dashed (–) line with a circle (o) marker, with a heavy line width.
hold onAdd the next line to existing plot.
hold offCreate a new axes for the next plotted line.
title(“My Title”)Add a lable to a plot.

Using tables

ExampleDescription
data.HeightYardsExtract the variable HeightYards from the table data.
data.HeightMetters = data.HeightYards*0.9144Derive a table veriable from existing data

Logicals

ExampleDescription
[5 10 15] > 12Compare a vector to the value 12.
v1(v1 > 6)Extract all elements in v1 that are greater than 6.
x(x=999) = 1Replace all values in x that are equal to 999 with the value 1.

Programming

ExampleDescription
if x > 0.5 y=3 else y=4 endif x is greater than 0.5, set the value of y to 3. Otherwise, set the value of y to 4.
for c = 1:3 disp© endThe loop counter( c ) progresses through the values 1:3 (1, 2, and 3). The loop body displays each value of c.

翻译自MATLAB Onramp [这儿][1].

[1]:https://matlabacademy.mathworks.com/R2020a/portal.html?course=gettingstarted#chapter=15&lesson=1&section=1

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值