How to combind a 1d Matrix with a 3d Matrix to form a 4d Matrix?

I have a matrix A in the shape 10000x28x28 and a matrix B in the shape 10000x1 and I need them in the shape 28x28x1x10000 (Im trying to achieve this but my starting point is a little diffrent: https://de.mathworks.com/matlabcentral/answers/349616-how-to-train-a-network-with-non-image-data-mnist#answer_275489)
How can I do this?
Thanks in advance

 Accepted Answer

A = rand(10000,28,28);
B = rand(10000,1);
A = permute(A, [2 3 4 1]);
B = permute(B, [4 3 2 1]);
size(A)
ans = 1×4
28 28 1 10000
size(B)
ans = 1×4
1 1 1 10000
C = A.*B;
size(C)
ans = 1×4
28 28 1 10000

More Answers (0)

Asked:

on 14 Nov 2023

Commented:

on 15 Nov 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!