concatenating strings
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all, I have two cell arrays containing dates and times e.g. D{1}='11/06/29' '11/06/30' etc
D{2}='10:36' '10:35' etc My aim is to concatenate the two strings with a space in between, i.e. to end up with '11/06/29 10:36' '11/06/30 10:35' etc Can someone help please? I have not managed to solve this, although it seems trivial. Many thanks, Christina
0 件のコメント
採用された回答
Titus Edelhofer
2011 年 8 月 15 日
Hi Christina,
not too nice but working:
D{1}={'11/06/29' '11/06/30'};
D{2}={'10:36' '10:35'};
x = strcat(D{1}, '$', D{2});
x = strrep(x, '$', ' ');
Titus
0 件のコメント
その他の回答 (1 件)
Jan
2011 年 8 月 15 日
The type and dimensions of the input is not clear:
"D{1}='11/06/29' '11/06/30'"
Does D{1} contain a cell string?! Then D would be a nested cell. Or is D a {n x 2} cell string? It is hard to create a meaningful answer, if the data structure is not defined exactly...
Usually STRCAT is the best choice to concatenate cell strings. Let me guess:
D1 = {'11/06/29', '11/06/30'}
D2 = {'10:36' '10:35'}
R = strcat(D1, {' '}, D2);
It is necessary to use a cell string for the space, because for strange historical reasons STRCAT removes marginal spaces of processed cell strings.
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!