Convert cell array of cell arrays to matrix of matrices

 I can convert a cell array of matrices to matrix: 


 


>> C={[1,1]; [2,2]; [3,3]};

>> cell2mat(C)

ans =

     1     1

     2     2

     3     3

This is OK. But, I want to convert a cell array including other cell arrays to a matrix: 


 


>> C={{1,1}; {2,2}; {3,3}};    

>> cell2mat(C)

Error using cell2mat (line 53)

Cannot support cell arrays containing cell arrays or objects.

So, desired output is: 


 


>> mycell2mat({{1,1}; {2,2}; {3,3}})

ans =

     1     1

     2     2

     3     3

How to do this?


Edit:

I want to do same thing for multidimensional ones also: 


 


>> mycell2mat({{1,1;1,1}; {2,2;2,2}; {3,3;3,3}})

ans(:,:,1) =


     1     1

     1     1


ans(:,:,2) =


     2     2

     2     2


ans(:,:,3) =


     3     3

     3     3 

NOTE:-


Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.       

Answers: 

To be honest, I never liked cell2mat for being slow, so I've come up an alternative solution using comma-separated lists instead!

Transform a cell array of vectors 

This is fairly simple, just use the colon operator and concatenate all vectors vertically: 

 

C = {[1,1]; [2,2]; [3,3]}; 
SEE COMPLETE ANSWER CLICK THE LINK       
https://matlabhelpers.com/questions/convert-cell-array-of-cell-arrays-to-matrix-of-matrices.php

Comments

Popular posts from this blog

How to Perform LU Decomposition with Partial Pivoting in Matlab

Why Red, Green, Blue channels of image separetely are grayscaled (Matlab)?

How to MATLAB: Extract multiple parts of a matrix without using loops