正在加载图片...
MATLAB Lecture chool of mathematical Sciences xiamen Univers http://gdjpkc.xmu.edu.cn =147 258 369 MATLAB -Getting Started - Matrices and Arrays- Matrices and Magic Square → Entering Matrices 1. Initializing Variables in MaTLaB(变量) Var=expresston Assign data to the variable in an assignment statement(赋值语句) Input data into the variable from the keyboard Read data from a file Some rules on variable t Begin with a letter t Followed by any combination of letters, numbers and the underscore()character t Only the first 31 characters are significant Good programming practice Easy-to-remember( e.g. name, NAME, Name are different Use only lowercase letter( e.g. name is the best > aa =[1 2 34567891: create an arrays with 9 elements >>a=[1 23: 456:7891 create a 3X3 matrix a 6 >>b=[1,2,3;4,5,6:7,8,9]; >> [1 >>d=[a(1,2),7+3 MATLAB -Getting Started Matrices and Arrays Expressions - Variables 2. Initializing with Shortcut Expressions- by Colon Operator(冒号运算) First: iner: last > al=1: 9:8 obtain a row vector containing the integers from 1 >>a2=1:2:10; >>a3=10:-3:0 pi:0.3 > subal a(1: 2, 3)i obtain a matrix Al, which is a partition of matrix a with the first 2 elements of the 3rd column of a >>suba2=a(1:2,:); >>suba3=a(:;2) >>c=a(:[2,3,1])for each of the rows of matrix A, reorderMATLAB Lecture 1  School of Mathematical Sciences Xiamen University  http://gdjpkc.xmu.edu.cn  Lec1­3  ans =  1  2  3  4  5  6  7  8  9 MATLAB → Getting  Started → Matrices  and Arrays  → Matrices  and Magic  Square → Entering  Matrices  1.  Initializing Variables in MATLAB (变量) Var = expression ÿ Assign data to the variable in an assignment statement(赋值语句). ÿ Input data into the variable from the keyboard.  ÿ Read data from a file. Some rules on variable: ² Begin with a letter ² Followed by any combination of letters, numbers and the underscore ( _ ) character ² Only the first 31 characters are significant  ² Case sensitive Good programming practice Easy­to­remember ( e.g. name, NAME, Name are different )  Use only lowercase letter ( e.g. name is the best ) >> aa = [1 2 3 4 5 6 7 8 9]; % create an arrays with 9 elements >> a = [1 2 3; 4 5 6; 7 8 9] % create a 3×3 matrix  a =  1  2  3  4  5  6  7  8  9 >> b = [1,2,3; 4,5,6; 7,8,9]; >> c = [1 2; ­3 ­4]; >> d = [a(1,2), 7+3] MATLAB → Getting  Started → Matrices  and Arrays  → Expressions  → Variables  2.  Initializing with Shortcut Expressions ­ by Colon Operator ( 冒号运算 ) First : incr : last >> a1 = 1:9; % obtain a row vector containing the integers from 1 …  to 9 >> a2 = 1:2:10;  >> a3 = 10:­3:0; >> a4 = ­pi:0.3:pi;  >> suba1 = a(1:2,3); %obtain a matrix subA1, which is a partition …  of matrix A with the first 2 elements of the 3rd column of A >> suba2 = a(1:2,:); >> suba3 = a(:,2); >> C = a(:,[2,3,1]); %for each of the rows of matrix A, reorder …
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有