Filter löschen
Filter löschen

merging 3 columns into one

1 Ansicht (letzte 30 Tage)
salva
salva am 24 Aug. 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 Kommentar
Jan
Jan am 24 Aug. 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'?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 24 Aug. 2012
Bearbeitet: Jan am 24 Aug. 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));

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by