Borrar filtros
Borrar filtros

How can I mat2cell the array?

1 visualización (últimos 30 días)
Hang Vu
Hang Vu el 29 de Abr. de 2019
Editada: Hang Vu el 29 de Abr. de 2019
Suppose I have this:
v= {1 8 1 1 6 1 2 5 3 2 7 11 7 9 10 9};
How can I mat them as below? ( with array start and end as same number)
v= { [1 8 1] [1 6 1] [2 5 3 2] [7 11 7] [9 10 9] };

Respuesta aceptada

Stephen23
Stephen23 el 29 de Abr. de 2019
Editada: Stephen23 el 29 de Abr. de 2019
>> v = {1,8,1,1,6,1,2,5,3,2,7,11,7,9,10,9};
>> c = regexp(char([v{:}]),'(.).*?(??$1)','match');
>> c = cellfun(@double,c,'uni',0);
>> c{:}
ans =
1 8 1
ans =
1 6 1
ans =
2 5 3 2
ans =
7 11 7
ans =
9 10 9
  1 comentario
Hang Vu
Hang Vu el 29 de Abr. de 2019
Thank you so much!^^ you saved me 2 times. I just re-asked for previous question. Could you please take a look if you have time!

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 29 de Abr. de 2019
out = mat2cell([v{:}],1,[3,3,4,3,3]);
  1 comentario
Hang Vu
Hang Vu el 29 de Abr. de 2019
Editada: Hang Vu el 29 de Abr. de 2019
Thank you for the response!

Iniciar sesión para comentar.

Categorías

Más información sobre Cell Arrays 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!

Translated by