Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!news02.roc.ny.POSTED!33b9410e!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Newbie: Subtract a vector from m-n-p array?
References: <fpet32$rj1$1@fred.mathworks.com> <fpev1t$4nf$1@canopus.cc.umanitoba.ca> <fpf14u$1a3$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-CB6AA1.14071719022008@71-129-133-66.dollamir.com>
Lines: 31
X-Complaints-To: abuse-news@frontiernet.net
X-Trace: 52616e646f6d4956446f3631ec51d5f4586cbed77f01b8f514a00a05e21ff1f71868cbfdeb627edb89866f83221048eced3f438fa18fe7d43996caff19c36e20bcf3139963b1256236ead83d65c06e37ae31d9dd65c2e780a386d0b72acf42dc13f2616d3d1d097be053f5923464d68fbea7dc987d13e51fd9e5d05a383d708a
X-Abuse-Info: Please be sure to forward ALL headers so that we may process your complaint properly.
NNTP-Posting-Date: Tue, 19 Feb 2008 19:07:15 UTC
Date: Tue, 19 Feb 2008 19:07:15 GMT
Xref: news.mathworks.com comp.soft-sys.matlab:452477



In article <fpf14u$1a3$1@fred.mathworks.com>,
 "Volker K" <klinkv.NOSPAM@yahoo.de> wrote:

> 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!


bsxfun(@minus,M,permute(V,[3 2 1]))

But you still have to have enough memory for the result.

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.