1-1 Creating Matrice This example constructs a new matrix C by concatenating matrices a and b in a vertical direction: A= ones(2, 5)*6: %2-by-5 matrix of 6s B= rand(3, 5); %3-by-5 matrix of random values C=[A; BI Vertically concatenate A and B C 6.00006.00006.0000600006.0000 6.00006.00006.00006.00006.0000 0.61540.73820.93550.89360.8132 0.79190.1763091690.05790.0099 0.92180.40570.41030.35290.1389
1-1 Creating Matrice This example constructs a new matrix C by concatenating matrices A and B in a vertical direction: A = ones(2, 5) * 6; % 2-by-5 matrix of 6's B = rand(3, 5); % 3-by-5 matrix of random values C = [A; B] % Vertically concatenate A and B C = 6.0000 6.0000 6.0000 6.0000 6.0000 6.0000 6.0000 6.0000 6.0000 6.0000 0.6154 0.7382 0.9355 0.8936 0.8132 0.7919 0.1763 0.9169 0.0579 0.0099 0.9218 0.4057 0.4103 0.3529 0.1389
1-1 Creating Matrice Method 4: Generating a Numeric Sequence Because numeric sequences can often be useful in constructing and indexing into matrices and arrays MATLAB provides a special operator to assist in creating them The colon operator (first: last) generates a 1-by-n matrix(or vector) of sequential numbers from the first value to the last To generate a series that does not use the default of incrementing by 1, specify an additional value with the colon operator (first: step: last)
1-1 Creating Matrice Because numeric sequences can often be useful in constructing and indexing into matrices and arrays, MATLAB provides a special operator to assist in creating them. Method 4: Generating a Numeric Sequence The colon operator (first:last) generates a 1-by-n matrix (or vector) of sequential numbers from the first value to the last. To generate a series that does not use the default of incrementing by 1, specify an additional value with the colon operator (first:step:last)
1-1 Creating Matrice The default sequence is made up of incremental values each 1 greater than the previous one A=10:15 A 101112131415 To generate a series of numbers from 10 to 50, incrementing by 5, use A=10:5:50 A= 101520253035404550
1-1 Creating Matrice The default sequence is made up of incremental values, each 1 greater than the previous one: A = 10:15 A = 10 11 12 13 14 15 To generate a series of numbers from 10 to 50, incrementing by 5, use A = 10:5:50 A = 10 15 20 25 30 35 40 45 50
It can include negative numbers and fractional numbers as well A=-2.5:2.5 A 2.5000-1.5000-0.50000.50001.5000 2.5000 You can increment by noninteger values. This example increments by 0.2:A=3: 0.2: 3.8 A 3.00003.2000340003.60003.8000 To create a sequence with a decrementing interval specify a negative step value A=9:-1:1 A 98765432
It can include negative numbers and fractional numbers as well: A = -2.5:2.5 A = -2.5000 -1.5000 -0.5000 0.5000 1.5000 2.5000 You can increment by noninteger values. This example increments by 0.2: A = 3:0.2:3.8 A = 3.0000 3.2000 3.4000 3.6000 3.8000 To create a sequence with a decrementing interval, specify a negative step value: A = 9:-1:1 A = 9 8 7 6 5 4 3 2
Matrix Indexing This section explains how to use subscripting and indexing to access and assign values to the elements of a MATLAB matrix. It covers the following Accessing Single Elements Linear Indexing Accessing Multiple Elements
Matrix Indexing This section explains how to use subscripting and indexing to access and assign values to the elements of a MATLAB matrix. It covers the following: Accessing Single Elements Linear Indexing Accessing Multiple Elements