Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matrices and arrays Pekar Miriam. What is matrices? In MATLAB environment, a matrix is a rectangular array of number Vector - 1 by 1 row/ column matrix.

Similar presentations


Presentation on theme: "Matrices and arrays Pekar Miriam. What is matrices? In MATLAB environment, a matrix is a rectangular array of number Vector - 1 by 1 row/ column matrix."— Presentation transcript:

1 Matrices and arrays Pekar Miriam

2 What is matrices? In MATLAB environment, a matrix is a rectangular array of number Vector - 1 by 1 row/ column matrix

3 Creating matrices matr1=[1 2] matr2=[2 4,4 5] matr2 = 2 4 4 5 Check lines ; matr[] – empty matrix matr = 16 3 5 29 7 2 3 matr3=[3 4;2 3] matr3 = 3 4 2 3 matr1=[1 2] matr1 = 1 2 matr2=[2 4,4 5] matr3=[3 4;2 3] matr4=[2^4,3, 5,4*6+5, 7,[2,3]]

4 Creating matrices with functions We need to definite the variables first! >> matr_by_matr=[matr_by_vec,2*matr_by_vec] matr_by_matr = 1 3 5 2 6 10 6 10 14 12 20 28 >> vec=[1 3 5] vec = 1 3 5 >> matr_by_vec=[vec;4+2*vec] matr_by_vec = 1 3 5 6 10 14

5 Matrices length >> vec=[2 4 5; 4 7 6]; >> [row,col]=size(vec)‏ row = 2 col = 3 Vector length >> vec=[2 4 6]; >> L=length(vec)‏ L = 3

6 Function rand creating random matrices >> rand_mat=rand(2,0)‏ >> rand_mat=rand(2)‏ >> rand_mat=rand(2,3)‏ Fix - Round toward Zero - >> a=[2.4 3.7 4.4;2.2 3.5 5.4; 6.9 7.8 8.5]; >> fix(a); Randn – random with negative digits rand_mat = 0.0971 0.6948 0.9502 0.8235 0.3171 0.0344 rand_mat = 0.6787 0.7431 0.7577 0.3922 rand_mat = Empty matrix: 2-by-0

7 Indexing into a matrix a(1:2,3:4)=[3 6;8 4] Changing Matrix cells till last cell – with “end” - A(:,end)=[1;2;3;4;5]; 1234 1 2 3 4 Changing value of cell 10 a(1,1)=10 : - changing all cells a(:,3)=1 1 1 Changing a sub matrix 3 6 8 4

8 The load function 1 File -> open -> data.dat Create a data.dat file

9 File -> new -> M-Files M-Files >> data >> whos Name Size Bytes Class Attributes A 2x3 48 double Save in your directory Call to the file The load function 2

10 Workspace Easy watch all vectors and Matrices ans – Optional Variable Matr=zeros(row,col)‏ Matr=ones(row,col)‏ Transpose ‘ change row matrix to column matrix


Download ppt "Matrices and arrays Pekar Miriam. What is matrices? In MATLAB environment, a matrix is a rectangular array of number Vector - 1 by 1 row/ column matrix."

Similar presentations


Ads by Google