I have a 3D-matrix A
, with size lets say 3x12x100
. The first two dimensions define 3×12 matrices
, the latter one is simply the linear index. I want a very simple operation on these 100 matrices. For all these matrices, i want them multiplied with its conjugate transpose. With a very simple for loop, i can create this:
data = data;
A = zeros(100, 12, 12);
for i=1:100
A(i, :, :) = data(:, :, i)'*data(:, :, i);
end
But i like clean code, so i dont really prefer this for-loop. I have done some searching and sometimes find something like mtimesx
(which is a custom made MATLAB function from 2010). I think i am missing something very obvious (as usual), because this seems a fairly easy operation (its just an "element-wise" matrix multiplication).
permute
ing the matrices and adding singleton dimensions, then applying thedot
operator along the right dimension. I don’t think it is worth while to figure out how exactly to write this. The loop code you have will be clearer, and likely faster. – Cris Luengo800000
(so the result is that many24x24
matrices), which can easily take around 10 minutes. I have a lot more (simple multiply/add) operations preceding this calculation and these take less than a second. Got any tips? – user2501247