Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use functions like repmat, replicate, or kron in MATLAB

I want to convert the matrix b:

b(:,:,1) =
     1
b(:,:,2) =
     3
b(:,:,3) =
     5

to matrix c:

c(:,:,1) =
     1     1
     1     1
c(:,:,2) =
     3     3
     3     3
c(:,:,3) =
     5     5
     5     5

without using for loops. In matrix c, each 1x1 element of b is converted to a 2x2 block with the same value as the corresponding element in b.


2 Answers

you can just use indexing, which is usually quicker:

b([1 1],[1 1],:)
like image 156
Gunther Struyf Avatar answered Dec 12 '25 19:12

Gunther Struyf


If I understand you correctly then:

   c = repmat(b, [2 2 1])
like image 42
Dan Avatar answered Dec 12 '25 19:12

Dan