"randi(100)" Outputting Characters Instead of Integers
1 次查看(过去 30 天)
显示 更早的评论
In line 2 below, "randi(100)" is returning characters, including black spaces, instead of integers. What code is converting "randi(100)" to return characters above line XXX, and how can I change this code to return integers?
dstr=num2str(d);
name=strcat('d',dstr,'_',randi(100));
4 个评论
per isakson
2015-10-18
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91
采纳的回答
the cyclist
2015-10-18
编辑:the cyclist
2015-10-18
I think you might want
name=strcat('d',dstr,'_',num2str(randi(100)));
This will convert the number to its string equivalent, rather than the ASCII value corresponding to that value (which is what I assume is happening now).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!