transform a vector to a cell array

1 visualización (últimos 30 días)
allnab
allnab el 29 de Dic. de 2013
Comentada: allnab el 30 de Dic. de 2013
Hi,
c=[5 7 1 9 10]; I want to create a cell from this vector as:
d={[5 7 1] [7 1 9] [1 9 10]};
Thanks in advance.

Respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 29 de Dic. de 2013
Editada: Azzi Abdelmalek el 29 de Dic. de 2013
c=[5 7 1 9 10];
m=3;
out=arrayfun(@(x) c(x:x+m-1),1:numel(c)-m+1,'un',0)
  4 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 30 de Dic. de 2013
What do you mean? The result is exactly what you asked for. to see the result type
celldisp(out)
allnab
allnab el 30 de Dic. de 2013
Excuse me it works correctly now
thank you

Iniciar sesión para comentar.


Andrei Bobrov
Andrei Bobrov el 29 de Dic. de 2013
d = num2cell(c(hankel(1:3,3:numel(c))),2)
  3 comentarios
Jos (10584)
Jos (10584) el 30 de Dic. de 2013
This error is shown when the second input to hanker is empty:
hankel(1:3,[])
In the code above this occurs because,
  • 3:numel(c) is empty, because,
  • numel(c) is less then 3, so,
check the contents of c !
allnab
allnab el 30 de Dic. de 2013
Excuse me it works correctly now
thank you

Iniciar sesión para comentar.

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by