How to get [1 0 1 0] from '1010'

조회 수: 1 (최근 30일)
Durga Lal Shrestha
Durga Lal Shrestha 2014년 9월 29일
댓글: Durga Lal Shrestha 2014년 9월 30일
Is there any built-in function or easiest way to get [1 0 1 0] from '1010' (character array)?
I have used for loop, but is there any other way to get the results?
str = '1010';
vec = zeros(length(str),1);
for i=1:length(str)
vec(i) = str2double(str(i));
end

채택된 답변

Stephen23
Stephen23 2014년 9월 29일
편집: Stephen23 2014년 9월 29일
Try this:
'1010' - '0'
or equivalently:
'1010' - 48
  댓글 수: 1
Durga Lal Shrestha
Durga Lal Shrestha 2014년 9월 30일
Thank you. This is that easy.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 9월 29일
str2double(regexp('1010','\d','match'))

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by