concatenating strings
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Titus Edelhofer
on 15 Aug 2011
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 Comments
More Answers (1)
Jan
on 15 Aug 2011
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.
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!