MATLAB

Create matrix from 1 to N in MATLAB1 min read

In MATLAB, you can create a matrix with elements from 1 to n using the following methods:

Using the colon notation:




Using the meshgrid function:

Using the reshape function:

Using the repmat function:

Using the bsxfun function :

You may also like: MATLAB Array Examples

Using a for loop:

Note that, the above methods will create a matrix of size nxn with elements from 1 to n^2. You can adjust the methods to suit your requirements.

Leave a Comment