Create matrix
Create a matrix in Matlab
% create 2x5 matrix of zeros
X = zeros(2,5)
0 0 0 0 0
0 0 0 0 0
% create matrix of ones
X = ones(2,5)
1 1 1 1 1
1 1 1 1 1
% create matrix of any repeated number (using ones or repmat)
X = 3 * ones(2,5)
3 3 3 3 3
3 3 3 3 3
X = repmat(3,[2,5])
3 3 3 3 3
3 3 3 3 3
% create matrix of NaN's
X = nan(2,5)
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
% create matrix of random numbers (Normally Gaussian distributed)
X = randn(2,5)
-0.0068 -0.7697 -0.2256 -1.0891 0.5525
1.5326 0.3714 1.1174 0.0326 1.1006
% create a vector and matrix of increasing numbers
Z = 1:10
1 2 3 4 5 6 7 8 9 10
X = reshape( Z, 5, 2)'
1 2 3 4 5
6 7 8 9 10
Text array
% create string and cell array of identical/repeated text
T = repmat("mytext",[2,5]) % string array
"mytext" "mytext" "mytext" "mytext" "mytext"
"mytext" "mytext" "mytext" "mytext" "mytext"
T = repmat({'mytext'},[2,5]) % cell array
{'mytext'} {'mytext'} {'mytext'} {'mytext'} {'mytext'}
{'mytext'} {'mytext'} {'mytext'} {'mytext'} {'mytext'}