From: Kai Wang on 21 Apr 2010 15:07 Hi, My first time posting question here. I have an array "A" with size (m X m X n), basically n concatenated square matrices. Is there any faster way to invert each matrix A(:,:,i) instead of using for loop such as: for i=1:n B(:,:,i)=inv(A(:,:,i)); end Thanks!
From: James Tursa on 21 Apr 2010 15:34 "Kai Wang" <coolarhoo(a)gmail.com> wrote in message <hqnico$atj$1(a)fred.mathworks.com>... > Hi, > > My first time posting question here. > > I have an array "A" with size (m X m X n), basically n concatenated square matrices. Is there any faster way to invert each matrix A(:,:,i) instead of using for loop such as: > > for i=1:n > B(:,:,i)=inv(A(:,:,i)); > end Pre-allocate B first. Also, what are you using the inverses for? Usually using backslash is a better option if you are solving linear equations. James Tursa
From: Bruno Luong on 21 Apr 2010 15:41 You could use my FEX tool: http://www.mathworks.com/matlabcentral/fileexchange/24260-multiple-same-size-linear-solver B=SliceMultiSolver(A,eye(m)); Bruno
From: Kai on 24 Apr 2010 16:57 Thanks for the reply! I mainly use it to invert between covariance and precision matrices to do some statistical computation. From time to time I could figure out some way to avoid involving covariance or precision matrices explicitly. I was just wondering if there's any array manipulation trick or any one has written some function to do that without explicit for-loops, similar to how we avoid loops by vectorization in some other simple calculations. "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hqnjvd$8p4$1(a)fred.mathworks.com>... > "Kai Wang" <coolarhoo(a)gmail.com> wrote in message <hqnico$atj$1(a)fred.mathworks.com>... > > Hi, > > > > My first time posting question here. > > > > I have an array "A" with size (m X m X n), basically n concatenated square matrices. Is there any faster way to invert each matrix A(:,:,i) instead of using for loop such as: > > > > for i=1:n > > B(:,:,i)=inv(A(:,:,i)); > > end > > Pre-allocate B first. Also, what are you using the inverses for? Usually using backslash is a better option if you are solving linear equations. > > James Tursa
|
Pages: 1 Prev: Speeding up a simple routine. Next: how can I generate an ROI polygon given a logical mask? |