how to concatnate cells within a column

1 回表示 (過去 30 日間)
andrew
andrew 2013 年 8 月 14 日
i have a column of cells that i would like to group/concatnate into one row for example:
Carboplatin & pemetrexed maintenance pemetrexed docetaxel
should become this: Carboplatin & pemetrexed||maintenance pemetrexed||Docetaxel
how do i do this without having to manually input the following code:
a=strcat (data2.REGIMEN{1},'||',data2.REGIMEN{2},'||',data2.REGIMEN{3});
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 14 日
Can you provide a short example with expected result?
andrew
andrew 2013 年 8 月 14 日
for example column contains{5,6,7,8,9,10,11,12,13,14...etc} and
outcome should be in one cell {5,6,7}, {8,9,10,11},

サインインしてコメントする。

回答 (2 件)

dpb
dpb 2013 年 8 月 14 日
編集済み: dpb 2013 年 8 月 15 日
s=char(d.reg(1));
for i=2:length(d.reg)
s=strcat(s,['||' char(d.reg(i))]);
end
Adding the "||" made trying to use comma list a pita in any way I could think of otomh, anyways...

F.
F. 2013 年 8 月 14 日
I think you should try this:
% code
strcat( sprintf( '%s||', Data2 .REGIMEN{1:end-1} ) , Data2.REGIMEN{end} )
OR
% code
Tmp = strcat( Data2 .REGIMEN(1:end-1), '||' );
strcat( [ Tmp{:} ] , Data2.REGIMEN{end} )

カテゴリ

Help Center および File ExchangePredictive Maintenance Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by