"randi(100)" Outputting Characters Instead of Integers
古いコメントを表示
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 日
編集済み: per isakson
2015 年 10 月 18 日
That's the way strcat works ( str as in string)
>> strcat( 97:107 )
ans =
abcdefghijk
Is this what you want?
>> dstr = 'hello';
>> name=strcat('d',dstr,'_',num2str( randi(100) ));
>> name
name =
dhello_82
balsip
2015 年 10 月 18 日
per isakson
2015 年 10 月 18 日
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91
balsip
2015 年 10 月 18 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!