concatenating strings

3 visualizzazioni (ultimi 30 giorni)
Christina
Christina il 15 Ago 2011
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

Risposta accettata

Titus Edelhofer
Titus Edelhofer il 15 Ago 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

Più risposte (1)

Jan
Jan il 15 Ago 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.
If speed matters, this function is 10 times faster, but needs to be compiled: FEX: CStrCatStr.
  1 Commento
Christina
Christina il 15 Ago 2011
sorry, my bad. The structure looked different in the preview but I failed to check. Thanks for the answer, anyway.

Accedi per commentare.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by