MATLAB Basics(10/40) Variables and Arrays > Initialization using keyboard input √input() value input('Enter an input value:') Enter an input value:1.25 value 1.2500 name input('What is your name:''s' What is your name:Selim name Selim CDHAW 细月济大学 TONGJI UNIVERSITY
MATLAB Basics(10/40) Variables and Arrays ➢ Initialization using keyboard input ✓ input() • value = input( 'Enter an input value: ' ) Enter an input value: 1.25 value = 1.2500 • name = input( 'What is your name: ', 's' ) What is your name: Selim name = Selim
MATLAB Basics(11/40) Multidimensional Array >Multidimensional Arrays ·c(:,,1)=[135;246; c(,2)=7911;81012]; >>whos Name Size Bytes Class c 2x3x2 96 double array >>c c(l)= 1 5 2 4 6 c2) 9 11 @日济大学 AW 8 10 12 TONGJI UNIVERSITY
MATLAB Basics(11/40) Multidimensional Arrays ➢ Multidimensional Arrays • c(:,:,1)=[1 3 5; 2 4 6]; c(:,:,2)=[7 9 11; 8 10 12]; >> whos Name Size Bytes Class c 2x3x2 96 double array >> c c(:,:,1) = 1 3 5 2 4 6 c(:,:,2) = 7 9 11 8 10 12
MATLAB Basics(12/40) Multidimensional Array X Storing in Memory Two-dimensional Column major order Multidimensional Arrays array subscript incremented first,second,third,... (1,1,1),(2,1,1),(1,2,1),(2,2,1),(1,1,2), (2,1,2),(1,2,2),(2,2,2) >Accessing Multidimensional arrays with a Single Subscript The elements will be accessed in the order in CPHAW which they were allocated in memory 细凡济大学 TONGJI UNIVERSITY
MATLAB Basics(12/40) Multidimensional Arrays ➢ Storing in Memory • Two-dimensional : Column major order • Multidimensional Arrays : array subscript incremented first, second, third, … (1,1,1), (2,1,1), (1,2,1), (2,2,1), (1,1,2), (2,1,2), (1,2,2), (2,2,2) ➢ Accessing Multidimensional arrays with a Single Subscript • The elements will be accessed in the order in which they were allocated in memory
MATLAB Basics(13/40) Multidimensional Array Example √A=[4101;829;757] B(:,:,1)=[4101;829;757] B(,:,2)=[625;474;152] (column major order) 6 2 5 4 10 13 A(4) 16 B(6) 8 2 9 4 7 4 B(12) 2 5 8 11 14 17 7 5 7 5 2 3 6 9 12 15 18 B(,,1) @月两大学 B(,2) TONGJIUNIVERSITY
MATLAB Basics(13/40) Multidimensional Arrays 6 10 2 13 5 16 4 11 7 14 4 17 1 12 5 15 2 18 4 1 10 4 1 7 8 2 2 5 9 8 7 3 5 6 7 9 Example ✓ A=[4 10 1;8 2 9;7 5 7] A(4) ✓ B(:,:,1)=[4 10 1;8 2 9;7 5 7] B(:,:,2)=[6 2 5;4 7 4;1 5 2] B(:,:,1) B(:,:,2) B(6) B(12) (column major order)
MATLAB Basics(14/40) Subarrays >A=410162;82947;75715;03458] 4 10 1 5 9 13 17 A(1:4,5) A(:,5) A(1,2) 8 2 9 4 7 A(:,end) A(5) 2 6 10 14 18 A(17:20) A(2:4,2:3) 5 7 1 5 A([234],[23]) 3 11 15 19 CPHAW 3 4 5 8 4 8 12 16 20 同碎大学 TONGJI UNIVERSITY
MATLAB Basics(14/40) Subarrays 4 1 10 5 1 9 6 13 2 17 8 2 2 6 9 10 4 14 7 18 7 3 5 7 7 11 1 15 5 19 0 4 3 8 4 12 5 16 8 20 A(1,2) A(5) A(2:4,2:3) A([2 3 4],[2 3]) A(1:4,5) A(:,5) A(:,end) A(17:20)' ➢ A=[4 10 1 6 2;8 2 9 4 7;7 5 7 1 5 ;0 3 4 5 8]