concatenating strings
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
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
0 Commenti
Più risposte (1)
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.
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!