|
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
[Prev in Thread] | Current Thread | [Next in Thread] |