How do I change a 2D char array to double array

1 回表示 (過去 30 日間)
Seung Woo Ham
Seung Woo Ham 2018 年 6 月 1 日
コメント済み: Seung Woo Ham 2018 年 6 月 1 日
I have a char array like this
val =
'1,106,54,40;421,389,234,21 '
'592,391,259,20;2174,391,240,20 '
'1,40,28,29;2863,1,139,36;2471,386,247,24;3224,1,114,30;3654,1,95,38;3780,76,60,29;1579,391,101,20'
This is 2D char array. For example,
val(1,1) = '1'
val(1,2) = ','
What I want to do is transforming this to double array
[1,106,54,40;421,389,234,21] (This case will be 2×4 double array)
[592,391,259,20;2174,391,240,20] (Also 2×4 double array)
[1,40,28,29;2863,1,139,36;2471,386,247,24;3224,1,114,30;3654,1,95,38;3780,76,60,29;1579,391,101,20] (7×4 double array)
My array may have empty row in 2D char array too. For example,
''
This has to be 0×0 double array
How can I do this? Thank you so much!
  2 件のコメント
Seung Woo Ham
Seung Woo Ham 2018 年 6 月 1 日
Actually, my 2D char array is much larger than this. So I have to use a loop function to handle this.
Stephen23
Stephen23 2018 年 6 月 1 日
@Seung Woo Ham: do the matrices always have four columns?

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

採用された回答

KSSV
KSSV 2018 年 6 月 1 日
val = {'1,106,54,40;421,389,234,21 ' '592,391,259,20;2174,391,240,20 ' '1,40,28,29;2863,1,139,36;2471,386,247,24;3224,1,114,30;3654,1,95,38;3780,76,60,29;1579,391,101,20' };
iwant = cellfun(@str2num,val,'un',0)
  1 件のコメント
Seung Woo Ham
Seung Woo Ham 2018 年 6 月 1 日
Wow... You are a real MVP. Thank You!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by