Matlab random string
Matlab random string
(OP)
Hi there
I would like to ask if there is any random string generator function in Matlab.
Thanks for your time
I would like to ask if there is any random string generator function in Matlab.
Thanks for your time





RE: Matlab random string
I don't believe there is one but it should be a fairly simple function to code. I can make one for you if you want?
David
RE: Matlab random string
Many thanks for your interest. I would be of course really obliged if you could do that.
Manos
RE: Matlab random string
If you want to add more letters of characters to the list of what can be generated you are free to (as long as the number of characters doesn't exceed 100 the script will still work).
David
RE: Matlab random string
Try these functions:
The first one generates a random string where repetitions are allowed. The second one generates a random string where repetitions are not allowed.
CODE
% generates a random string of lower case letters of length n
LetterStore = char(97:122); % string containing all allowable letters (in this case lower case only)
String = LetterStore(ceil(length(LetterStore).*rand(1,n)));
CODE
% generates a random string of lower case letters of length n
% n must be less than the number of possible letters
% elements of the returned string are exclusive
LetterStore = char(97:122); % string containing all allowable letters (in this case lower case only)
Idx = randperm(length(LetterStore));
String = LetterStore(Idx(1:n));
M
--
Dr Michael F Platten
RE: Matlab random string
All I can say is my function works and I don't know all the builtin functions because I don't use it all that often.
RE: Matlab random string
Want to learn all the tricks? Frequent that group as well as this site. The group's FAQ is good too.
RE: Matlab random string
I can understand that my solution wasn't the most Matlabish in style, but it still worked and it's not bad programming, just not using the Matlab functions. :)
David