# concatenate 2 vectors as string

5 visualizzazioni (ultimi 30 giorni)
Elysi Cochin il 12 Ott 2022
Modificato: Stephen23 il 12 Ott 2022
I have 2 vectors
a = [87.46 85.38 85.99 85.49 88.56 85.67]
b = [0.16 1.97 2.38 2.38 1.63 1.81]
I wanted to save the values of a and b in a string cell as
{87.46±0.16, 85.38±1.97, 85.99±2.38, 85.49±2.38, 88.56±1.63, 85.67±1.81}
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Stephen23 il 12 Ott 2022
Modificato: Stephen23 il 12 Ott 2022
"I wanted to save the values of a and b in a string cell as"
The MATLAB documentation states "Avoid using cell arrays of strings. When you use cell arrays, you give up the performance advantages that come from using string arrays. "
You should use a string array, rather than a cell array of string scalars.

Accedi per commentare.

### Risposta accettata

Matt J il 12 Ott 2022
Modificato: Matt J il 12 Ott 2022
Why not as a string array?
a = [87.46 85.38 85.99 85.49 88.56 85.67];
b = [0.16 1.97 2.38 2.38 1.63 1.81];
c=a+string(char(177))+b
c = 1×6 string array
"87.46±0.16" "85.38±1.97" "85.99±2.38" "85.49±2.38" "88.56±1.63" "85.67±1.81"
If you really must have a cell array, then,
c=cellstr(c)
c = 1×6 cell array
{'87.46±0.16'} {'85.38±1.97'} {'85.99±2.38'} {'85.49±2.38'} {'88.56±1.63'} {'85.67±1.81'}
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### 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!

Translated by