merging 3 columns into one

1 次查看(过去 30 天)
salva
salva 2012-8-24
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 个评论
Jan
Jan 2012-8-24
Is it correct, that the input contains 9 rows, but the output only 3?
Does 'DE111'_'n.a.'_'08111000' mean 'DE111_n.a._08111000'?

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2012-8-24
编辑:Jan 2012-8-24
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));

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by