This document is designed to act as a tutorial for an individual who has had no prior
experience with Matlab.

  1. Start Matlab. After the program starts, you should see something similar to that
    shown in Figure 1 (the actual display may vary depending on the version of
    Matlab you have installed).

本文档旨在作为之前没有使用 Matlab 经验的个人的教程。

启动该教程 1. 启动 Matlab。程序启动后,您应该看到类似于下图所示的内容(实际显示可能因您安装的 Matlab 版本而异)。

Basic Matlab interface showing only Command Window

如果您的窗口不是这样显示的,则可能当前激活了不同的窗口。让我们更改外观并激活一些有用的窗口。首先,我们将开始一个新的 $\mathrm{m}$ 文件。要做到这一点,请使用 文件 $>$ 新建 $>$ 脚本 或者 文件 $>$ 新建 $>$ M 文件 这将启动一个可以编辑的新 M 文件(稍后会详细介绍)。这可能会在新窗口中打开编辑器,如图所示。

Screenshot of new m-file editor in new window
  1. We would like to be able to see both the editor and the Command Window at the
    same time. Go back to the m-file editor and select
    Desktop > Dock Editor
    This will attach the m-file editor to the Command Window
  2. We would also like to activate the Workspace window. To do this, go to the
    Command window and select
    Desktop > Workspace
    This will activate the Workspace window.
  3. You can now drag around the 3 activated windows (Command Window, m-file
    editor, and Workspace) to arrange the views as you like. To drag a window,
    simply click on the window and then drag the blue bar (see Figure 3). The Matlab
    interface should now similar to Figure 3.

4. 我们希望能够同时看到编辑器和命令窗口 同时。返回 m 文件编辑器并选择 桌面 > 程序坞编辑器 这会将 m 文件编辑器附加到命令行窗口 5. 我们还想激活工作区窗口。为此,请访问 命令窗口并选择 桌面 > 工作区 这将激活工作区窗口。 6. 您现在可以在 3 个激活的窗口(命令窗口、m-file 编辑器和工作区)以根据需要排列视图。要拖动窗口, 只需单击窗口,然后拖动蓝色条即可(参见图 3)。 MATLAB 界面现在应该类似于图 3。

MATLAB interface

Using Matlab

  1. Matlab stores most of its numerical results as matrices. Unlike some languages
    (C, C++, C#), it dynamically allocates memory to store variables. Therefore, it is
    not necessary to declare variables before using them. Let’s begin by simply
    adding two numbers. Click in the Command Window. You will see a flashing “|”
    symbols next to the “>>” symbol. Enter the following commands
  2. Type in “x = 3” then hit “enter”
  3. Type in “y = 2;” then hit “enter” (note the semicolon here!)
  4. Type “z = x + y” then hit “enter”
Basic Matlab interface showing only Command Window

All declared variables appear in the workspace. Recall that these values are stored as matrices. The “size” column tells us the dimension of the matrix. As expected, all these variables are $1 \times 1$ scalar values. To double check on value stored in this matrix, simply double click any of the variables in the Workspace.

  1. Now, let’s assume that $x$ and $y$ are actually components of a $2 D$ vector. Let’s construct the vector $\bar{v}=\left(\begin{array}{l}x \ y\end{array}\right)$. Note that we are making a column vector of size

2×1. We use the “[” to denote the start of a matrix and “]” to denote the end of the matrix. The command to construct the vector is shown below
&\gg \mathrm{v}=[\mathrm{x} ; \mathrm{y}] \
&\mathrm{v}= \
3 \
Also notice that in the workspace, the variable ” $\mathrm{v}$ ” is of size $2 \mathrm{x} 1$ as expected.

  1. In a similar fashion, if we want to create a horizontal vector, we use the space instead of the “,” to separate elements. For example
    12 & -3
    \end{array}\right] \
    &p= \
    &\qquad 12 \quad-3
    Once again notice that the variable “p” is created in the workspace and it is of size $1 \times 2$ as expected
  2. We can create a 2D matrix in a similar fashion. You can use the “[” to start the matrix, type in the first row with spaces in between elements, use a “;” to start the next row, and then repeat. Finally close the matrix with a “]”. For example, to create a $3 x 2$ matrix, we can use syntax like
    &\gg \mathrm{A}=\left[\begin{array}{llll}
    1 & 2 & ; & 3 & 4 ;
    \end{array}\right] \
    &A= \
    &\qquad \begin{array}{rr}
    1 & 2 \
    3 & 4 \
    12 & -3
    Notice that we used the variable ‘p’ as the last row. This is possible since the dimensions match.
  3. Matlab treats most variables as matrices, and therefore operations like addition, multiplication, etc. must be done with matrices whose dimensions are consistent. For example, we could enter
matlab代写数学代写 认准UprivateTA™

matlab代写请认准UprivateTA™. UprivateTA™为您的留学生涯保驾护航。