Encapsulated cell array (cell in cell) converting to 2D-array

Hello,
I´m searching for an efficient method to convert an cell-in-cell array, e.g. 1000 x 1 Cell, each filled with 1 x 33 cell to 1000 x 33 Cell array. This is my code so far including undesired for-loops:
cell_array = regexp(text_data, '\;', 'split'); % splitting textfile with semikolon seperated data (1000 x 1) x (1 x 33)
for i=1:length(cell_array)
single_data = cell2mat([cell_array{i,1}(1,1), cell_array{i,1}(1,16), cell_array{i,1}(1,31), cell_array{i,1}(1,32)]); % just extracting 4 relevant values
data = [data; single_data]; % collect data
end
It works so far, but for datasets up to 10e6 it takes too much time.
Thanks for your help!

回答 (1 件)

the cyclist
the cyclist 2019 年 8 月 26 日
編集済み: the cyclist 2019 年 8 月 26 日

0 投票

cellfun performs an operation on every cell in a cell array. This line is equivalent your for loop:
data = cellfun(@(x)cell2mat([x(1,1), x(1,16), x(1,31), x(1,32)]),cell_array,'unif',false);
I did not test it for speed.

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

製品

タグ

質問済み:

2019 年 8 月 26 日

編集済み:

2019 年 8 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by