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 23:19:02 +0000 (UTC)
Organization: TU Dresden
Lines: 48
Message-ID: <fpfo56$6tp$1@fred.mathworks.com>
References: <fpet32$rj1$1@fred.mathworks.com> <fpev1t$4nf$1@canopus.cc.umanitoba.ca> <fpf14u$1a3$1@fred.mathworks.com> <see-CB6AA1.14071719022008@71-129-133-66.dollamir.com>
Reply-To: "Volker K" <klinkv.NOSPAM@yahoo.de>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203463142 7097 172.30.248.38 (19 Feb 2008 23:19:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 19 Feb 2008 23:19:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1174616
Xref: news.mathworks.com comp.soft-sys.matlab:452531



Problem: I only have Matlab 7.2 :-(

I wonder that there's
 no possibility in MatLab to do these kind of operations:
> > M(:,:)-V(1)
> > M(:,:)-V(2)
> > M(:,:)-V(3)
> > M(:,:)-V(4)
> > ...
> > M(:,:)-V(end) 

I guess it is a common problem...


Doug Schwarz <see@sig.for.address.edu> wrote in message
<see-CB6AA1.14071719022008@71-129-133-66.dollamir.com>...
> 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.