简体   繁体   中英

Reshape mxn cell array to mxnxt 3D matrix in Matlab

I looked through past answers but I could find one that gave me a definitive answer for my case (weird as it seems simple).

I have a mxn cell array with each having a tx1 matrix and I would like to reshape this to a mxnxt 3D matrix. I saw a few example with permute and remat but did not get my answer there.

Thanks!

You just need cell2mat with a little of permute :

c = repmat({(1:4).'},2,3); %'// example cell array
result = permute(cell2mat(permute(c,[3 1 2])), [2 3 1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM