Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Trasform number in strings

조회 수: 1 (최근 30일)
pamela sulis
pamela sulis 2016년 3월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Stephen23
Stephen23 2016년 3월 21일
편집: Stephen23 2016년 3월 21일
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

답변 (1개)

Guillaume
Guillaume 2016년 3월 21일
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