How to concatenate strings and numbers with individual elements?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2021-1-12
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 个评论
Walter Roberson
2021-1-12
编辑:Walter Roberson
2021-1-12
"The free energy of " + strjoin(Elements + Vs, '') + " is" + result + "KJ"
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!