-
Notifications
You must be signed in to change notification settings - Fork 33
/
rep.m
44 lines (39 loc) · 1.2 KB
/
rep.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
% REP.m Replicate a matrix
%
% This function replicates a matrix in both dimensions.
%
% Syntax: MatOut = rep(MatIn,REPN);
%
% Input parameters:
% MatIn - Input Matrix (before replicating)
%
% REPN - Vector of 2 numbers, how many replications in each dimension
% REPN(1): replicate vertically
% REPN(2): replicate horizontally
%
% Example:
%
% MatIn = [1 2 3]
% REPN = [1 2]: MatOut = [1 2 3 1 2 3]
% REPN = [2 1]: MatOut = [1 2 3;
% 1 2 3]
% REPN = [3 2]: MatOut = [1 2 3 1 2 3;
% 1 2 3 1 2 3;
% 1 2 3 1 2 3]
%
% Output parameter:
% MatOut - Output Matrix (after replicating)
%
%
% Author: Carlos Fonseca & Hartmut Pohlheim
% History: 14.02.94 file created
% 22.01.03 tested under MATLAB v6 by Alex Shenfield
function MatOut = rep(MatIn,REPN)
% Get size of input matrix
[N_D,N_L] = size(MatIn);
% Calculate
Ind_D = rem(0:REPN(1)*N_D-1,N_D) + 1;
Ind_L = rem(0:REPN(2)*N_L-1,N_L) + 1;
% Create output matrix
MatOut = MatIn(Ind_D,Ind_L);
% End of function