Borrar filtros
Borrar filtros

vector of strings to cell array

2 visualizaciones (últimos 30 días)
John Petersen
John Petersen el 7 de Mzo. de 2013
I have a list of numbers as strings that I want to assign to a cellarray. I currently just do a for loop to make the assignment but want to know if there is a vectorized way to do it.
A = [1 2 3 4 5 6]';
strA = num2str(A);
B = cell(6,1);
for i=1:length(A)
B{i} = strA(i);
end

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Mzo. de 2013
B=arrayfun(@num2str,A,'un',0)
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 7 de Mzo. de 2013
Editada: Azzi Abdelmalek el 7 de Mzo. de 2013
or
B=cellstr(num2str(A))
John Petersen
John Petersen el 7 de Mzo. de 2013
The first answer works. Second one puts all of A in a single cell. Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings 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