how to randomly generate an alphabet within a given range ?
35 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(3 个)
Wayne King
2013-12-2
编辑:Wayne King
2013-12-2
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 个评论
Arjun P Kumar
2020-9-25
AB
AC
AD
AE
AF
let these be the options to randomly generate...how can i do that?
1 个评论
Sterling Baird
2020-10-21
编辑:Sterling Baird
2020-10-21
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
2021-6-27
编辑:Ramesh Singh
2021-6-30
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 个评论
Walter Roberson
2021-6-27
Your ranges are off
char(60:90) %what you use
('A':'Z')+0 %actual
Your use of > and < is confusing. Use >= and <=
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!