Documentation of expandvec

Global Index (all files) (short | long) | Local contents | Local Index (files in subdir) (short | long)

Function Synopsis

y = replicate(reps, vec)

Help text

 This function replicates a vector vec
 as often as defined in a vector reps
 into one vector

 Example: turn vec = [1 5 3], reps = [1 5 3] => y = [1 5 5 5 5 5 3 3 3]
 2nd Example: turn vec = [1 2 3 4], reps = [3 4 2 1] => y = [1 1 1 2 2 2 2 3 3 4]
 
 Quelle: Usenet,
         Message-ID: <derrico-A33B2E.22244112042002@news.newsguy.com>
 
 Author: John D'Errico

Listing of function expandvec



function y = replicate(reps, vec)

  n=sum(reps);
  ind=zeros(n,1);
  i=cumsum([1;reps(:)]);
  ind=sparse(i(1:(end-1)),1,1,n,1);
  ind=cumsum(ind);
  y=vec(ind);

% End of function
GEATbx: Main page  Tutorial  Algorithms  M-functions  Parameter/Options  Example functions  www.geatbx.com 

This document is part of version 3.7 of the GEATbx: Genetic and Evolutionary Algorithm Toolbox for use with Matlab - www.geatbx.com.
The Genetic and Evolutionary Algorithm Toolbox is not public domain.
© 1994-2005 Hartmut Pohlheim, All Rights Reserved, (support@geatbx.com).