From help-octave-request at bevo dot che dot wisc dot edu Fri Aug 22 04:28:22 1997 Subject: Re: adding vectors and matrices From: Ted dot Harding at nessie dot mcc dot ac dot uk (Ted Harding) To: aheit at physik dot uni-kassel dot de (Andreas Heitmann) Cc: help-octave at bevo dot che dot wisc dot edu Date: Fri, 22 Aug 1997 10:22:20 +0100 (GMT+0100) ( Re Message From: Andreas Heitmann ) > > I'm using octave for some time now, but I'm still wondering if there > is a simple way to add a fixed column vector to a number of other > column vectors stored in a matrix. Currently i'm using a loop like the > following: > > v=[1;2;3]; > for i=1:columns(x) > y(:,i)=x(:,i)+v; > endfor > > Is it possible to compute y without a loop statement? Hi, y = x + v*ones(1,columns(x)); will do it. I understand John Eaton plans to incorporate a syntax like y = x .+ v for a future release which will do the same thing (and the corresponding thing if v is a row vector with as many elements as x has columns, i.e. add v to each row of x). Best wishes, Ted. (Ted dot Harding at nessie dot mcc dot ac dot uk)