输入矩阵 |
对于你而言获得MATLAB开始的最基本的方式是学习如何处理矩阵。启动MATLAB和顺着下面的例子继续下去: 你能够使用几种不同的方式输入矩阵到MATLAB。 (1)进入一个元素的详细列表。 (2)从外部数据文件加载矩阵。 (3)使用函数产生矩阵 (4)你自己的在M文件中的函数创造矩阵 启动通过输入Dürer's矩阵作为一个它的元素的列表。你只能不得不遵守以下基本规则: (1)使用空格或逗号分开一列的元素。 (2)使用一个分号,“;”表示每行的结束。 (3)使用方括号包围整个元素的列表。 输入Dürer's矩阵,在命令窗口中简单键入 A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1] MATLAB显示你刚刚输入的矩阵 A = 这个矩阵上的数字和在版画中相同。一旦你已经输入矩阵,在MATLAB工作空间中它是自然而然的记住。你能够很方面的引用它作为A。现在在工作空间中你有A,看看多么有趣啊。为什么它有魔力? |
Entering Matrices
The best way for you to get started with MATLAB is to learn how to handle matrices. Start MATLAB and follow along with each example.
You can enter matrices into MATLAB in several different ways:
(1)Enter an explicit list of elements.
(2)Load matrices from external data files.
(3)Generate matrices using built-in functions.
(4)Create matrices with your own functions in M-files.
Start by entering Dürer's matrix as a list of its elements. You only have to follow a few basic conventions:
(1)Separate the elements of a row with blanks or commas.
(2)Use a semicolon, ; , to indicate the end of each row.
(3)Surround the entire list of elements with square brackets, [ ].
To enter Dürer's matrix, simply type in the Command Window
A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
MATLAB displays the matrix you just entered.
A =
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
This matrix matches the numbers in the engraving. Once you have entered the matrix, it is automatically remembered in the MATLAB workspace. You can refer to it simply as A. Now that you have A in the workspace, take a look at what makes it so interesting. Why is it magic?