Categories
2. After the Advance

Repmat Matlab

Repmat in Matlab is one of the commands in Matlab which is used for array manipulations. This command gives output in the form of an array repetition of the original array. Here array is a collection of the number of elements, data, information, etc. An array is represented within square brackets in Matlab. We can add any number of elements into the array. The array can be a single-dimensional or multiple dimensional. If the array is multidimensional then it is called Matrix. If we wish to create a matrix in Matlab then we need to separate the elements by (   ‘; ’ ) within the array.

What is Repmat Matlab?

Repmat command repeats the elements of an array in output. Repetition is depended on parameter list, therefore every time we need to declare parameters within a bracket after repmat command. There are multiple ways to write the repmat function according to the parameter list.

1. repmat (75,4)

The Different Repmat Function according to the parameter is given below:

Syntax:

repmat(number, no of rows and column)

This command produces box matrix with the same number of rows and columns, here the number is ‘ 75 ’ and the number of rows and columns are four. Matlab code and implementation is given below;

Matlab EditorMatlab Command window ( Output )
Arr = repmat(75 , 4 ) >> UntitledArr =75    75    75    7575    75    75    7575    75    75    7575    75    75    75

Example 1: Matlab implementation

box matrix

2. repmat ( arr,2)

Syntax:

repmat (array name, number of rows and columns)

In this type arr is the name of any array .here we declare the elements of the array we can add any elements into the array. this command produces an output of two rows and two columns. Matlab code and output script illustrated in the following table.

Matlab EditorMatlab Command window ( Output )
arr = [ 2  4  3 8 9]Arr =repmat(arr,2) arr =2     4     3     8     9Arr =2     4     3     8     9     2     4     3     8     92     4     3     8     9     2     4     3     8     9

Example 2: Matlab implementation

 two rows and two columns

3. repmat ( arr, 5,2)

Syntax:

repmat (array name, no of rows, no of columns)

Example 3: Matlab implementation

In previous example dimensions of the matrix were restrict but in this example, we can give the number of rows and number of columns separately. Here the number of rows is five and the numbers of columns are 2. Matlab code and output illustrated in the following table.

Matlab EditorMatlab Command window ( Output )
arr = [ 54 65 23]Arr = repmat(arr , 5 ,2)arr =54    65    23Arr =54    65    23    54    65    2354    65    23    54    65    2354    65    23    54    65    2354    65    23    54    65    2354    65    23    54    65    23
Matlab implementation
Matlab EditorMatlab Command window ( Output )
Arr = repmat(75,5,2)Arr =75    7575    7575    7575    7575    75
Matlab command window

4. repmat(arr ,[1 3 2])

Syntax :

repmat(arr,[no of rows, no of the column, no of blocks])

Example 4: Matlab implementation

If we want output block multiple times then we can use this command. Here arr is the name of the array, one is the number of rows,3 is the number of columns and two is the repetition of the output matrix.

Matlab EditorMatlab Command window ( Output )
arr = [ 4 2 ; 7 8 ]Arr = repmat(arr ,[1 3 2])arr =4     27     8Arr (:,:,1) =4     2     4     2     4     27     8     7     8     7     8Arr (:,:,2) =4     2     4     2     4     27     8     7     8     7     8
block multiple times

5. arr=1:3& arr=( 1:3 ) ‘

Syntax :

array name = (range) and array name = (range) ’

Example 5: Horizontal & Vertical Implementation

In this type input is a range of numbers. 1:3 represents numbers from 1 to 3 (1, 2, 3) in a horizontal manner. And ( 1:3 ) ’ represents numbers from 1 to 3 (1, 2, 3) in a vertical manner. Matlab code and output illustrated in the following table.

Matlab EditorMatlab Command window ( Output )
arr = 1:3Arr = repmat(arr , 3 , 2 )>> Untitledarr =1     2     3Arr =1     2     3     1     2     31     2     3     1     2     31     2     3     1     2     3
arr=(1:3)’Arr=repmat(arr,3,2)Arr=123Arr =1     12     23     31     12     23     31     12     23     3

Horizontal Vertical

Horizontal implementation

Vertical Implementation

Vertical implementation

Leave a Reply

Your email address will not be published. Required fields are marked *