How to concatenate strings and numbers with individual elements?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BHARAT CHARAN GOUD MARUPALLI
am 12 Jan. 2021
Bearbeitet: Walter Roberson
am 12 Jan. 2021
I would like to concatenate the strings and numbers. If my input is Elements = {'H', 'N', 'Fe', 'Ni', 'Ti'} and Values = [1 1 0.3 0.5 0.2], I want the ouput of result = HNFe0.3Ni0.5Ti0.2. For the value '1', it should not assign anything.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Jan. 2021
Elements = {'H', 'N', 'Fe', 'Ni', 'Ti'}
Values = [1 1 0.3 0.5 0.2];
Vs = string(Values);
Vs(Values == 1) = "";
strjoin(Elements + Vs, '')
2 Kommentare
Walter Roberson
am 12 Jan. 2021
Bearbeitet: Walter Roberson
am 12 Jan. 2021
"The free energy of " + strjoin(Elements + Vs, '') + " is" + result + "KJ"
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!