Clear Filters
Clear Filters

merging 3 columns into one

1 view (last 30 days)
salva
salva on 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 Comment
Jan
Jan on 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'?

Sign in to comment.

Answers (1)

Jan
Jan on 24 Aug 2012
Edited: Jan on 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));

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!