Borrar filtros
Borrar filtros

merging 3 columns into one

1 visualización (últimos 30 días)
salva
salva el 24 de Ag. de 2012
Dear all, I have
A={
'DE111' 'n.a.' '08111000'
'DE112' '081155001' '08115054'
'DE112' '081155002' '08115013'
'DE112' '081155002' '08115015'
'DE112' '081155003' '08115010'
'DE112' '081155003' '08115021'
'DE112' '081155003' '08115037'
'DE112' '081155004' '08115002'
'DE112' '081155004' '08115022'}
and I want to merge these 3 columns in one as follows
Anew={
'DE111'_'n.a.'_'08111000'
'DE112'_'081155001'_'08115054'
'DE112'_'081155002'_'08115013'
}
Is there a way of doing this?
thanks
  1 comentario
Jan
Jan el 24 de Ag. de 2012
Is it correct, that the input contains 9 rows, but the output only 3?
Does 'DE111'_'n.a.'_'08111000' mean 'DE111_n.a._08111000'?

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 24 de Ag. de 2012
Editada: Jan el 24 de Ag. de 2012
s = size(A);
out = cell(s(1),1);
for jj = 1:s(1)
out{jj} = sprintf('%s_%s_%s', A{jj, :});
end
Or without a loop (to be true: STRCAT contains the loop then):
out = strcat(A(:, 1), '_', A(:, 2), '_', A(:, 3));

Categorías

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