Is there a analogue of Matlab's `bsxfun` for matrix multiplication/division?

428 Views Asked by At

I need to multiply a list vectors by a list of matrices. Currently I am doing it with a for loop:

for k=1:N
    x(:,k)= A(:,:,k) \ b(:,k);
end

Can I write this without the for loop?

1

There are 1 best solutions below

0
On

If you're really looking for a solution (which might be slower ; you need to profile), I'd store my matrices in a cell array (such that A(:,:,k) = A{k}). Then:

x = reshape(  blkdiag(A{:})\b(:)   ,   numel(b)/N,   N  );