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:
b([1 1],[1 1],:)
If I understand you correctly then:
c = repmat(b, [2 2 1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With