K = tril(ones(3,4)) % 3-by-4 matrix whose lower triangular part is all ones. J = blkdiag(rand(2,2),ones(3,2)) % 5-by-4 block diagonal matrix I = logspace(0,2,6) % 1-by-6 matrix of log-spaced numbers from 10^0 to 10^2 ![]() = meshgrid(1:5) % 5-by-5 grids of numbers A = zeros(4,5) % 4-by-5 matrix of all zerosī = ones (2,3) % 2-by-3 matrix of all onesĬ = rand(3,3) % 3-by-3 matrix of uniform random numbers in ĭ = randn(2,5) % 2-by-5 matrix of standard normally distributed numbers D = Īlternatively, there are several functions that will generate matrices for us. A = 1:10 % start at 1, increment by 1, stop at 10ī = 1:2:10 % start at 1, increment by 2, stop at 10Ĭ = 10:-1:3 % start at 10, decrement by 1, stop at 3 A = We can often exploit patterns in the entries to create matrices more succinctly. We, (and Matlab) always refer to rows first and columns second. We say that this matrix is of size 4-by-3 indicating that it has 4 rows and 3 columns. ![]() Entries on each row are separated by a space or comma and rows are separated by semicolons, (or newlines). We begin by simply entering data directly. There are a number of ways to create a matrix in Matlab.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |