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

3 ビュー (過去 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'))
  1 件のコメント
Durga Lal Shrestha
Durga Lal Shrestha 2014 年 9 月 30 日
Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by