Path: news.mathworks.com!not-for-mail
From: "chaintzean " <chaintzean@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: inv(rand(6,6,2)) question
Date: Mon, 24 Nov 2008 21:29:01 +0000 (UTC)
Organization: PSP Investments
Lines: 42
Message-ID: <ggf6at$ino$1@fred.mathworks.com>
References: <ggf2da$898$1@fred.mathworks.com> <ggf2oi$dfo$1@fred.mathworks.com> <ggf39d$mlm$1@fred.mathworks.com>
Reply-To: "chaintzean " <chaintzean@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227562141 19192 172.30.248.35 (24 Nov 2008 21:29:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 24 Nov 2008 21:29:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 999148
Xref: news.mathworks.com comp.soft-sys.matlab:502942


"Hydroman S" <amirgsalem@gmail.com> wrote in message <ggf39d$mlm$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ggf2oi$dfo$1@fred.mathworks.com>...
> > "Hydroman S" <amirgsalem@gmail.com> wrote in message <ggf2da$898$1@fred.mathworks.com>...
> > 
> > > 
> > > shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate inverse? 
> > > 
> > 
> > No.
> > 
> > Bruno
> 
> fine, now if I put it in a loop, I would think that it would work, but it also doesn't:
> 
> for i=1:6
> x=inv(rand(3,3,i)); 
> end
> 
> ??? Error using ==> inv
> Input arguments must be 2-D.
> 
> 
> 
> I also applied squeeze, but it does not work as well.  My problem is why? since inside the loop, rand(3,3,1) is gives a square matrix
> 
> for i=1:2
> x=squeeze(inv(rand(3,3,i))); 
> end
> 
> 

It seems like you don't understand how rand() works.  If what you really need to do is to inverse sub-matrices of a random 3-dimensional matrix (which I doubt), then looping on it would have to be done that way:

X = rand(6,6,2);

for i=1:2
    X_inv(:,:,i) = inv(squeeze(X(:,:,i)));
end

rand(3,3,i) generates a 3x3x(i) array which cannot be inverted (except for i=1, of course).  Also, why would you squeeze outside of the inv call?  By the way, you don't even need to squeeze in my example above, I just wanted to illustrate proper use.