"randi(100)" Outputting Characters Instead of Integers

3 Ansichten (letzte 30 Tage)
balsip
balsip am 18 Okt. 2015
Kommentiert: balsip am 18 Okt. 2015
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 Kommentare
per isakson
per isakson am 18 Okt. 2015
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91
balsip
balsip am 18 Okt. 2015
That would work, too! Thanks again.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by