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: <muy8ww0bjwd.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:ChAVsbI7+e1Ie1jm/BMks0otykM=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 54
Date: Thu, 17 Jul 2008 11:38:42 -0400
NNTP-Posting-Host: 155.34.163.114
X-Complaints-To: news@ll.mit.edu
X-Trace: llnews 1216308386 155.34.163.114 (Thu, 17 Jul 2008 11:26:26 EDT)
NNTP-Posting-Date: Thu, 17 Jul 2008 11:26:26 EDT
Xref: news.mathworks.com comp.soft-sys.matlab:480011



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

> I think the communication issue stems from the fact i didn't
> understand the number of array dimensions could be above 3.
> To me, a matrix with rows, columns, and pages was always a
> 3D matrix (as it forms a 3D 'block'). Evidently this is not
> the case.
>
> The reshape and permute functions you suggest do achieve
> what I wanted thanks:
> M=reshape([ai_col(:),bi_col(:),ci_col(:),di_col(:)],16,3,2,2);
> M=permute(M,[3 4 2 1]);
>
> For each of the 3 sets of 16 2x2 arrays contained within M I
> want to find the product in the dimension of the 16 2x2
> matrices. I have been using your ndfun mex file as follows:
>
> prodH=zeros(2,2,3);
> for p=1:3
>     q=p;
>     prodH(1,q)=ndfun('mprod',M(:,:,p,:))
> end
>
> However, i get the error that 'assignment has more
> non-singleton rhs dimensions than non-singleton subscripts'.
> Could you show me how to do this correctly pls? Thanks for
> your help.

prodH is 2x2x3.  You index it with only two indices.  What do you want
the third index to be?

For each thing you are trying to assign (in your case, only one!),
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

-Peter