Convert 4 cell arrays into 4 columns in matrix
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi guys!
Can anybody help me with converting 4 cell arrays that have different lengths into a matrix with 4 columns? I've been searching in the forum but I cannot get it to work. Thanks in advance!
5 comentarios
  KALYAN ACHARJYA
      
      
 el 14 de Dic. de 2020
				"Yes, I am! Do you maybe know how I can fill in the blanks with NaN?"
Here
https://www.mathworks.com/matlabcentral/answers/267216-how-to-make-each-vector-of-equal-size-in-a-cell-by-adding-nan#answer_209066
Respuestas (1)
  Adam Danz
    
      
 el 14 de Dic. de 2020
        
      Editada: Adam Danz
    
      
 el 24 de Dic. de 2020
  
      This answer shows how to combine column vectors of different lengths into a matrix with NaN values as fillers. 
Applied to your data, that would look like,  
maxNumRow = max(cellfun(@(c) numel(c), orientation_target));  % max length
mPad = cell2mat(cellfun(@(c){padarray(c,[maxNumRow-numel(c),0],NaN,'Post')},orientation_target)); 
Sample of the result 
mPad(1:10,:)
ans =
    28   -87   -44    42
   -15   -79    44     8
   -70    -3   -18    30
    50    -1   -41    75
   -38   -87    32   -67
   -82   -57    12    65
    78    24   -24   -90
   -63    66    -6    54
    46    45    86    13
    -1     0    83   -46
6 comentarios
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



