Azzera filtri
Azzera filtri

merging 3 columns into one

1 visualizzazione (ultimi 30 giorni)
salva
salva il 24 Ago 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 Commento
Jan
Jan il 24 Ago 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'?

Accedi per commentare.

Risposte (1)

Jan
Jan il 24 Ago 2012
Modificato: Jan il 24 Ago 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));

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by