help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set array values from 3 vectors


From: Przemek Klosowski
Subject: Re: set array values from 3 vectors
Date: Tue, 30 Aug 2011 14:26:42 -0400
User-agent: Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20110816 Thunderbird/6.0

On 08/30/2011 11:12 AM, Andy Buckle wrote:
On 30 August 2011 11:25, carbonmetrics<address@hidden>  wrote:
I have a canvas=zeros(1000,365), in which 1000=number of projects and
365=days of the year,
a startdate and an enddate vector, and a value vector.

what i would like to do is to place the values [value vector] in the canvas
array,
where the indices are>  startdate and<  enddate.

if the canvas would be a vector, and the value a scalar then
'canvas(startdate:enddate)=value' would do the job.

I can't get it done doing a loop, but of course I would much rather
vectorize the code.

It looks like a frequent question, but I could not find anything on this,
does anybody have an idea?

Thanks!
Henk

It's probably just me being slow. I don't quite get it.

Could you write a short script that is self-contained, and does what
you want? It can be slow and loopy. Then it is easier for anyone
trying to help. They can write vectorised versions and compare to your
reference implementation.


I think he means

projects=5 ; # 1000 in his example
startdate=[1 30 50 70 90];enddate=[50 90 180 200 250];value=[1 3 5 7 9];
for i=1:projects
 canvas(i,startdate(i):enddate(i)) = value(i);
end
sum(canvas)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]