How to convert from cell array to multidimensional array?

4 ビュー (過去 30 日間)
Chandrama Sarker
Chandrama Sarker 2017 年 7 月 24 日
コメント済み: Chandrama Sarker 2017 年 7 月 24 日
I have a cell array that is 1x10,000 with each cell containing a multidimensional array of (7x7x6). How can I convert from cell array to multidimensional array that has a dimensions of (7,7,6,10000)?

採用された回答

per isakson
per isakson 2017 年 7 月 24 日
編集済み: per isakson 2017 年 7 月 24 日
Loops are allowed if one remember to pre-allocate
num = nan( 7, 7, 6, 10000 );
for jj = 1 : 10000
num(:,:,:,jj) = C{jj};
end
and they are fast enough
>> cssm
Elapsed time is 0.048869 seconds.
Elapsed time is 0.037956 seconds.
ans =
1
where cssm is
m = randn( 7,7,6 );
C = repmat( {m}, [1,10000] );
tic
num = nan( 7, 7, 6, 10000 );
for jj = 1 : 10000
num(:,:,:,jj) = C{jj};
end
toc
tic
n02 = cat( 4, C{:} );
toc
all( num(:)==n02(:) )
  1 件のコメント
Chandrama Sarker
Chandrama Sarker 2017 年 7 月 24 日
Thank You Per, it works well. I have also found out one more way to do that: out = Q= cat(4, C{:});

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by