Efficient slicing of cell array?

20 ビュー (過去 30 日間)
EGTork
EGTork 2015 年 3 月 20 日
編集済み: EGTork 2015 年 3 月 20 日
I have a cell array of the form:
c =
[1x100 double]
[2x150 double]
[3x200 double]
And I would like to create a 6x50 matrix consisting of all rows and the first 50 columns of each constituent matrix. Is there an efficient way to do this?

採用された回答

Andrei Bobrov
Andrei Bobrov 2015 年 3 月 20 日
variant
cell2mat(cellfun(@(x)x(:,1:50),C,'un',0));
  1 件のコメント
EGTork
EGTork 2015 年 3 月 20 日
編集済み: EGTork 2015 年 3 月 20 日
Thanks, Andrei. For reference, I compared this cell array approach against directly indexing a matrix to create a submatrix. The cell array solution took about 5X as long, which is not bad considering the extra flexibility provided by cell arrays.
Specifically, I took a cell array containing five 10x100,000 matrices, and used your approach to generate a 50x75,000 submatrix. I compared this to directly indexing into a 50x100,000 matrix to create a 50x75,000 submatrix. For matrices of this size, there was a 5X penalty for using cell arrays instead of a matrix. For smaller matrices, the penalty was somewhat higher (~10X).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by