How can I transform a number to string with space using num2str?
Mostra commenti meno recenti
What is the result of "num2str(1,'%2d')"? I think it should be " 1", but the results is "1". I mean there is no space before "1". Actually, the result of "num2str(1,'%02d')" is "01", and the result of "num2str(1,'%-2d')" is "1". And, the result of "sprintf('%2d',1)" is " 1".
How can I transform a number to string with space using num2str?
Risposta accettata
Più risposte (2)
Walter Roberson
il 5 Dic 2013
Use sprintf instead of nu2str()
sprintf('%2d', 1)
3 Commenti
Jung-Woo
il 5 Dic 2013
Simon
il 5 Dic 2013
Hi!
Please compare
sprintf('%2d\n',[1;11])
and
sprintf('%d\n',[1;11])
Walter Roberson
il 9 Dic 2013
numt = num(:).'; %make sure it is row vector
rem100 = mod(numt, 100);
lead2600 = mod((numt - rem100) ./ 100, 26) + 65;
longstr = sprintf('%c%2d\n', [lead2600; rem100]);
strs = regexp(longstr, '\n', 'split');
Jung-Woo
il 9 Dic 2013
1 Commento
Walter Roberson
il 9 Dic 2013
You cannot use num2str() for this purpose. In situations in which every entry ends up with a leading blank, num2str() will strip off the leading blank.
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!