フィルターのクリア

"randi(100)" Outputting Characters Instead of Integers

1 回表示 (過去 30 日間)
balsip
balsip 2015 年 10 月 18 日
コメント済み: balsip 2015 年 10 月 18 日
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
per isakson 2015 年 10 月 18 日
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91
balsip
balsip 2015 年 10 月 18 日
That would work, too! Thanks again.

サインインしてコメントする。

採用された回答

the cyclist
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).
  1 件のコメント
balsip
balsip 2015 年 10 月 18 日
Thanks for the quick reply, Cyclist. That did the trick. Very green here, so it's much appreciated.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by