help-octave
[Top][All Lists]
Advanced

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

How to vectorize this code?


From: Brian Kaczynski
Subject: How to vectorize this code?
Date: Wed, 11 Apr 2018 13:23:54 +0200

Hello Octavians!

I have a long vector DIV (containing about 150,000 elements) which contains integers only from 32 to 64, inclusive.  I want to create a longer vector containing 1's repeated DIV(1) times, 2's repeated DIV(2) times, 3's repeated DIV(3) times, etc.  This is how I'm doing it now:

  ind = [];
  for j = 1:length(DIV)
  ind = [ind ; j*ones(DIV(j),1)];
  end

I know there are some experts at vectorizing for-loop code like this.  Who can give this a shot?

Thanks!
-Brian

reply via email to

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