how to randomly generate an alphabet within a given range ?
47 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
roshan varkey
el 2 de Dic. de 2013
Comentada: Ramesh Singh
el 30 de Jun. de 2021
i want to randomly generate an alphabet between a given range,for example a range of A-J,and i want matlab to pick a alphabet between this range...how do i do it? i am a beginner at matlab and would really appreciate ur help!ThankYou!
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 2 de Dic. de 2013
Editada: Azzi Abdelmalek
el 2 de Dic. de 2013
s='A':'J'
str=s(randi(numel(s)))
0 comentarios
Más respuestas (3)
Wayne King
el 2 de Dic. de 2013
Editada: Wayne King
el 2 de Dic. de 2013
Do you want capital or lower case letters? You can just use the ascii representations
char(97:106)
or
char(65:74)
If you have the Statistics Toolbox you can randomly sample from those "populations"
idx = randsample(65:74,5); %choose five letters at random
char(idx)
0 comentarios
Arjun P Kumar
el 25 de Sept. de 2020
AB
AC
AD
AE
AF
let these be the options to randomly generate...how can i do that?
1 comentario
Sterling Baird
el 21 de Oct. de 2020
Editada: Sterling Baird
el 21 de Oct. de 2020
I suggest asking as a new question and linking to this post, but I wouldn't be surprised if this question has been asked already somewhere.
Ramesh Singh
el 27 de Jun. de 2021
Editada: Ramesh Singh
el 30 de Jun. de 2021
it is the function that can generate random alphabet between the given alphabet.. one more thing you can also input the ascii code of alphabet
function ra=randa(a,b)
%a=any number or alphabet
%b=any number or alphabet
l=double(a);
k=double(b);
if a>=65&b<=90
ra=char(randi([l k],1,1));
elseif a>=95&b<=122
ra=char(randi([l k],1,1));
else
error('you are entering wrong number or alphabet');
end
end
2 comentarios
Walter Roberson
el 27 de Jun. de 2021
Your ranges are off
char(60:90) %what you use
('A':'Z')+0 %actual
Your use of > and < is confusing. Use >= and <=
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!