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.
you can just use indexing, which is usually quicker: