MATLAB: How to i attain a matrix with 1 to n

columninputrow

when i prompt a user for a value for m,n how do i attain a matrix such that the first row of a matrix be 1 to m for eg.if a user input a value of 9 for m the first row of a matrix will be: 1 2 3 4 5 6 7 8 9
similarly, if the user enter a value of 6 for n, then my first column will be 1 2 3 4 5 6
please kindly advise,thanks alot!

Best Answer

See my comment above. If you want us to fill the remaining elements with zeros.
dims = input('Provide the row and column dimension of the matrix in brackets, e.g. [6 9] \n');
% the user enters [6 9]
X = zeros(dims(1),dims(2));
X(:,1) = 1:dims(1);
X(1,:) = 1:dims(2);