Pergunta

Does anyone know how I can reshape these two columns:

     1     1
     1     1
     1     1
   379   346
   352   363
   330   371
   309   379
   291   391
   271   402
   268   403
     1     1
     1     1
   406   318
   379   334
   351   351
   329   359
   307   367
   287   378
   267   390
   264   391

into these four columns:

     1     1    1      1
     1     1    1      1
     1     1    406  318  
   379   346    379  304 
   352   363    351  351 
   330   371    329  359 
   309   379    307  367
   291   391    287  378
   271   402    267  390
   268   403    264  391

That is, how to reshape a matrix that is the size of Nx2 into a size 10xM in matlab?

Foi útil?

Solução

One solution using mat2cell, splitting every 10 rows. Probably easier to understand, because no 3d-matrices are used:

cell2mat(mat2cell(x,repmat(10,size(x,1)/10,1),size(x,2))')

Second solution using reshape and permute, should be faster but I did not try it.:

reshape(permute(reshape(x,10,[],size(x,2)),[1,3,2]),10,[])
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top