Change data type of entire cell array?

I have a 1 x 2500 cell array created from a .txt file. Each cell has one long string of many individual numbers that I need. EX: '1 2 3 4 5 6 7 8 9'
I need to make each number in the entire cell array a double value type. str2double doesn't work because I need to split up the string. I tried using strsplit but maybe I was doing it wrong.
Any advice?

1 件のコメント

Tyler Bodnarik
Tyler Bodnarik 2020 年 11 月 18 日
newA = cellfun(@(x) strsplit(x), BM, 'UniformOutput', false);
With this I now have a cell array with each cell being it's own seperate cell array. However I need to get every value to be a double data type.
str2double(newA) outputs NaN

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

回答 (1 件)

madhan ravi
madhan ravi 2020 年 11 月 18 日

0 投票

cellfun(@(x) sscanf(x, '%d').', Cell_array, 'un', 0)

1 件のコメント

Tyler Bodnarik
Tyler Bodnarik 2020 年 11 月 18 日
I tried this out. It just outputted 1s and 0s.

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

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2020 年 11 月 18 日

コメント済み:

2020 年 11 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by