Updated March 23, 2023
Introduction to 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 Editor | Matlab Command window ( Output ) |
Arr = repmat(75 , 4 )
|
>> Untitled
Arr = 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 |
Example #1: Matlab implementation
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 Editor | Matlab Command window ( Output ) |
arr = [ 2 4 3 8 9]
Arr =repmat(arr,2)
|
arr =
2 4 3 8 9 Arr = 2 4 3 8 9 2 4 3 8 9 2 4 3 8 9 2 4 3 8 9 |
Example #2: Matlab implementation
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 Editor | Matlab Command window ( Output ) |
arr = [ 54 65 23]
Arr = repmat(arr , 5 ,2) |
arr =
54 65 23 Arr = 54 65 23 54 65 23 54 65 23 54 65 23 54 65 23 54 65 23 54 65 23 54 65 23 54 65 23 54 65 23 |
Matlab Editor | Matlab Command window ( Output ) |
Arr = repmat(75,5,2) | Arr =
75 75 75 75 75 75 75 75 75 75 |
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 Editor | Matlab Command window ( Output ) |
arr = [ 4 2 ; 7 8 ]
Arr = repmat(arr ,[1 3 2]) |
arr =
4 2 7 8 Arr (:,:,1) = 4 2 4 2 4 2 7 8 7 8 7 8 Arr (:,:,2) = 4 2 4 2 4 2 7 8 7 8 7 8 |
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 Editor | Matlab Command window ( Output ) |
arr = 1:3
Arr = repmat(arr , 3 , 2 ) |
>> Untitled
arr = 1 2 3 Arr = 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 |
arr=(1:3)’
Arr=repmat(arr,3,2) |
Arr=
1 2 3 Arr = 1 1 2 2 3 3 1 1 2 2 3 3 1 1 2 2 3 3 |
Horizontal Vertical
Vertical Implementation
Conclusion
There is the various command used in array manipulations. Repmat is one of the important functions used to create an array as well as the matrix. Along with creation it also used for manipulation and mathematical operations. It is one of the simplest methods because just by declaring parameters we can form and manipulate arrays and matrix.
Recommended Articles
This is a guide to Repmat in Matlab. Here we discuss the Introduction, What is Repmat Matlab along with different examples implemented with outputs. You can also go through our other related articles to learn more–