Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!bloom-beacon.mit.edu!llnews!53ab2750!not-for-mail
From: Peter Boettcher <boettcher@ll.mit.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorise a reshape loop
References: <g5krk2$77v$1@fred.mathworks.com>
Message-ID: <muyd4l78h3a.fsf@G99-Boettcher.llan.ll.mit.edu>
Organization: MIT Lincoln Laboratory
User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.0 (gnu/linux)
Cancel-Lock: sha1:dYiqzWMjkEb+QODunbQmnGw+XlU=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 52
Date: Mon, 21 Jul 2008 10:08:57 -0400
NNTP-Posting-Host: 155.34.163.114
X-Complaints-To: news@ll.mit.edu
X-Trace: llnews 1216648595 155.34.163.114 (Mon, 21 Jul 2008 09:56:35 EDT)
NNTP-Posting-Date: Mon, 21 Jul 2008 09:56:35 EDT
Xref: news.mathworks.com comp.soft-sys.matlab:480671



"Dave Brackett" <davebrackett@hotmail.com> writes:

>> figure out the dimensions of the right-hand side.  Try it first
>> mentally, and if you're not sure, assign it to a variable and ask
>> MATLAB to tell you what the size is.
>> 
>> Then, look at where you want to assign it.  Your assignment indices
>> must provide a place in the output which exactly matches the
>> dimensions of the right side.
>> 
>> For instance, I can't say:
>> 
>> A(1, 2:4) = B(1:4, 2);
>> 
>> Why?
>> left side is 1x3, right side is 4x1
>> 
>> I can't say:
>> A(1,1,2:4) = B(1,2:4)
>> 
>> Why?
>> left side is 1x1x3, right side is 1x3

Pay VERY careful to the examples above, again.  In the second example, I
am not asking for the size of B, but for the size of entire right-hand
side.  B is at least 1x4, but the indexing makes it 1x3.

> ok, the size of my right side is 2x2x90x16 and the required
> size for my left is 2x2x90x1 so I have written this as:
>
> prodH=zeros(2,2,length(freq),1);
> for p=1:length(freq)
>     q=p;
>     prodH(:,:,q,1)=ndfun('mprod',M(:,:,q,:))
> end

The size of the left side IS NOT 2x2x90x1.  q is a scalar, so the left
side is 2x2x1x1. The right side, I assume, is 2x2x1x16.  But don't guess
or believe me.  If you can't figure out your dimension issues, I meant
what I said about "if you're not sure, assign it to a variable and ask
MATLAB to tell you what the size is".

tmp = ndfun('mprod', M(:,:,q,:));
size(tmp)

I could take a guess at fixing it, but only you know what you want
where.  Actually, I think ndfun('mprod') is not doing what you think
it's is doing.  Do what I suggest above, and I think you'll see what I
mean.  Then go back and read the help for ndfun, carefully.


-Peter