Path: news.mathworks.com!not-for-mail
From: "Volker K" <klinkv.NOSPAM@yahoo.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Newbie: Subtract a vector from m-n-p array?
Date: Tue, 19 Feb 2008 16:46:22 +0000 (UTC)
Organization: TU Dresden
Lines: 53
Message-ID: <fpf14u$1a3$1@fred.mathworks.com>
References: <fpet32$rj1$1@fred.mathworks.com> <fpev1t$4nf$1@canopus.cc.umanitoba.ca>
Reply-To: "Volker K" <klinkv.NOSPAM@yahoo.de>
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 1203439582 1347 172.30.248.35 (19 Feb 2008 16:46:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 19 Feb 2008 16:46:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1174616
Xref: news.mathworks.com comp.soft-sys.matlab:452423



Well, I need to subtract each element of the q-by-1 vector V
once from the m-by-n matrix M.

I thought I could create a m-by-n-by-q array A and then
subtract each element of V. I cannot create m-n from V with
repmat because the arrays are getting too big and ill run
out of memory. (q is about 10000, m and n are 101).

So here's the example again:

M(:,:)-V(1)
M(:,:)-V(2)
M(:,:)-V(3)
M(:,:)-V(4)
...
M(:,:)-V(end)

But thanks so far!


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fpev1t$4nf$1@canopus.cc.umanitoba.ca>...
> In article <fpet32$rj1$1@fred.mathworks.com>,
> Volker K <klinkv.NOSPAM@yahoo.de> wrote:
> 
> >I have a m-n-p array A and a q-1 vector V.
> 
> >What I would like to do:
> 
> >A(:,:,1)-V(1)
> >A(:,:,2)-V(2)
> >A(:,:,3)-V(3)
> 
> >Anyone has an idea how to do that without a loop?
> 
> If we are to assume that you -only- want to do the first three
> elements of the vector, then
> 
> A(:,:,1:3) - repmat(V(1:3),size(A,1),size(A,2),1)
> 
> If you meant to do the whole vector V, then there is a
problem:
> you indicated that the third dimension of A is of length p,
> but that the vector V is of length q-1, and unless it happens
> that p = q-1 then you either have two many or two few
elements of V
> to generalize this without further clarification from you.
> -- 
>    "Beware of bugs in the above code; I have only proved
it correct,
>    not tried it."                                    --
Donald Knuth