Clear Filters
Clear Filters

"randi(100)" Outputting Characters Instead of Integers

1 view (last 30 days)
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 Comments
per isakson
per isakson on 18 Oct 2015
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 18 Oct 2015
Edited: the cyclist on 18 Oct 2015
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 Comment
balsip
balsip on 18 Oct 2015
Thanks for the quick reply, Cyclist. That did the trick. Very green here, so it's much appreciated.

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!