"randi(100)" Outputting Characters Instead of Integers
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
per isakson
il 18 Ott 2015
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91
Risposta accettata
the cyclist
il 18 Ott 2015
Modificato: the cyclist
il 18 Ott 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).
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!