フィルターのクリア

Converting string array to float array

40 ビュー (過去 30 日間)
Ankita Tondwalkar
Ankita Tondwalkar 2022 年 3 月 27 日
編集済み: Stephen23 2022 年 3 月 27 日
I have a string array of the format
"[1,1]"
"[2,1]"
"[3,1]"
How can you convert into double array?

採用された回答

Stephen23
Stephen23 2022 年 3 月 27 日
編集済み: Stephen23 2022 年 3 月 27 日
S = ["[1,1]";"[2,1]";"[3,1]"]
S = 3×1 string array
"[1,1]" "[2,1]" "[3,1]"
Method 1:
M = sscanf(join(S,''),'[%f,%f]',[2,Inf]).'
M = 3×2
1 1 2 1 3 1
Method 2:
M = cell2mat(arrayfun(@str2num,S,'uni',0))
M = 3×2
1 1 2 1 3 1
Method 3:
M = reshape(str2double(regexp(join(S),'\d+','match')),2,[]).'
M = 3×2
1 1 2 1 3 1

その他の回答 (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