Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Trasform number in strings

1 Ansicht (letzte 30 Tage)
pamela sulis
pamela sulis am 21 Mär. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi! I want to trasform
[674 631 1 10 144]
in
{'674' '631' '1' '10' '144'},
I have tried to use num2str but it gives me {'674 631 1 10 144'} that is different from that I want as result.
  1 Kommentar
Stephen23
Stephen23 am 21 Mär. 2016
Bearbeitet: Stephen23 am 21 Mär. 2016
Actually num2str does not output a cell as you wrote, just a character array:
>> S = num2str([674 631 1 10 144])
S = 674 631 1 10 144
>> class(S)
ans = char

Antworten (1)

Guillaume
Guillaume am 21 Mär. 2016
Two simple options:
1. loop (explicit or with arrayfun):
a = [874 631 1 10 144];
c = arrayfun(@num2str, a, 'UniformOutput', false)
2. Using sprintfc an undocumented function that's been in matlab for a while. Since it's undocumented it may disappear in a future version or may change behaviour
a = [874 631 1 10 144];
c = sprintfc('%d', a)

Community Treasure Hunt

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

Start Hunting!

Translated by