Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorise a reshape loop
Date: Thu, 17 Jul 2008 09:50:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 65
Message-ID: <g5n4kd$jtp$1@fred.mathworks.com>
References: <g5krk2$77v$1@fred.mathworks.com> <g5kthu$svb$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216288205 20409 172.30.248.37 (17 Jul 2008 09:50:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 17 Jul 2008 09:50:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1338633
Xref: news.mathworks.com comp.soft-sys.matlab:479928



"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g5kthu$svb$1@fred.mathworks.com>...
> "Dave Brackett" <davebrackett@hotmail.com> wrote in message 
> <g5krk2$77v$1@fred.mathworks.com>...
> > Hi, I am having trouble vectorising the below for loop. Can
> > anyone help me please? I am expecting M to consist of 3 rows
> > of 2x2 matrices each with 16 deep. Thanks in advance.
> 
> Try that again? What is the shape of M?
> Is it 3x2x2x16? This is inconsistent with
> what you have shown below.
> 
> 
> > for p=1:3
> > q=p;
> > M=reshape([a(:,q) c(:,q) b(:,q) d(:,q)].', 2, 2, []);
> > end
> > 
> > where a,b,c,d are 3x16 matrice such as: 
> > (imaginary parts can be ignored)
> >    1.0000 + 0.0000i   0.9999 + 0.0000i   0.9999 + 0.0001i
> 
> Um, that is a 16x3 matrix.
> 
> Anyway, what loop?
> 
> Since you overwrite M on each pass
> through, that non-loop does nothing
> but define M at the last value of p.
> 
> We can't help you unless you will think
> clearly enough about what you want to
> explain it.
> 
> You might start by preallocating M to be
> the proper size. Use zeros.
> 
> John
> 
> 

Ok, sorry for any confusion, I will try again.

I want a 3D matrix, consisting of in this case, 3 2x2
matrices (as shown below) plus 15 additional 2x2 matrices
stacked behind them, giving 3 rows of 16 2x2 matrices all
contained within one matrix.

[a1 b1  [a2 b2  [a3 b3
 c1 d1]  c2 d2]  c3 d3]

The amended 'for' loop shown below intends to do this. I
have changed it so M should store each 2x2 matrix, but it is
isn't right as I'm not sure how to do it right.

for p=1:3
q=p;
r=1:16;
M(:,q,r)=reshape([a(:,q) c(:,q) b(:,q) d(:,q)].', 2, 2, []);
end

As you rightly point out a,b,c, and d are indeed 16x3
matrices. Preallocation of M can come later.

Hopefully that explanation is a bit clearer. Thanks.