help-octave
[Top][All Lists]
Advanced

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

RE: Repeating bug (error: subscript indices must be either positiveinteg


From: John W. Eaton
Subject: RE: Repeating bug (error: subscript indices must be either positiveintegers or logicals)
Date: Wed, 27 Apr 2011 16:22:04 -0400

On 27-Apr-2011, address@hidden wrote:

| I wrote a shuffle function below but there is probably already one out
| there somewhere.
|  
| function chars = shuffle(str)
| %shuffle(str) Return shuffled string
| % Randomly permute characters of string and return shuffled version
| %
|   chars = str;
|   for idx = 1:length(str)
|     swp = randpick(1:length(str));
|     tmp = chars(idx);
|     chars(idx) = chars(swp);
|     chars(swp) = tmp;
|   end
| endfunction

You could use

  str(randperm (numel (str))

to randomly permute the elements of STR.

jwe


reply via email to

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