0
votes

In my current analysis, I am trying to multiply a matrix (flm), of dimension nxm, with the inverse of a matrix nxmxp, and then use this result to multiply it by the inverse of the matrix (flm).

I was trying using the following code:

flm = repmat(Data.fm.flm(chan,:),[1 1 morder]); %chan -> is a vector 1by3
A = (flm(:,:,:)/A_inv(:,:,:))/flm(:,:,:);

However. due to the problem of dimensions, I am getting the following error message: Error using ==> mrdivide Inputs must be 2-D, or at least one input must be scalar. To compute elementwise RDIVIDE, use RDIVIDE (./) instead.

I have no idea on how to proceed without using a for loop, so anyone as any suggestion?

1
P.S. I copy one thing wrong (the second flm doesn't have parameters) so it suposed to look like this: flm = repmat(Data.fm.flm(chan,:),[1 1 morder]); A = (flm(:,:,:)/A_inv(:,:,:))/flm(:,:,:);tTimoteof
Welcome to SO! Note that you can edit your own question by clicking the "edit" button below the question. Also, it's nice if you try to format the code as nice as you can (for instance not having 27 spaces in front of the code).Stewie Griffin
How do you calculate the inverse of a 3D-matrix? That's not possible. Are each of the 2D-slices inverted separately? Also, why calculate the (undefined) inverse of A and use division, instead of just multiplying it?Stewie Griffin
I don't want to invert the 3D matrix, what I need is to inverse each layer of the matrix A_inv (yes each 2D-slices is inverted seperatly) and then multiply it by the Data.fm.flm matrix (which is 2by2 ). The name A_inv is so I can know that the matrix I got (earlier in the program )is not yet the matrix A but an inversion matrix of the one I want.tTimoteof

1 Answers

1
votes

I think you are looking for a way to conveniently multiply matrices when one is of higher dimensionality than the other. In that case you can use bxsfun to automatically 'expand' the smaller matrix.

x  = rand(3,4);
y = rand(3,4,5);
bsxfun(@times,x,y)

It is quite simple, and very efficient.

Make sure to check out doc bsxfun for more examples.