how to initialize a table in matlab in matlab

To initialize a table/matrix in Matlab, you can do the following:

main.m
% Initialize a 3-by-3 matrix with random values
myMatrix = rand(3,3);

% Initialize a matrix with specific values
myMatrix = [1 2 3; 4 5 6; 7 8 9];
148 chars
6 lines

The first example creates a 3-by-3 matrix with random values using the rand function. The second example initializes a matrix with specific values using brackets [] and separating rows with semicolons ;.

related categories

gistlibby LogSnag