How to add string to the beginning of each element in a string array?

136 次查看(过去 30 天)
Hi there,
I'm trying to append the string 'Syl_' to the beginning of each element in a string array. For example, if I have the string array
s1 = string(1:4)
Columns 1 through 4
"1" "2" "3" "4"
I want to attach 'Syl_' to the beginning of each element, yielding:
Columns 1 through 4
"Syll_1" "Syll_2" "Syll_3" "Syll_4"
Any help

采纳的回答

TADA
TADA 2018-12-12
strcat('Syl_', s1)
ans =
1×4 string array
"Syl_1" "Syl_2" "Syl_3" "Syl_4"
  2 个评论
TADA
TADA 2018-12-12
编辑:TADA 2018-12-12
also works with a cell array of strings:
c1 = cellfun(@num2str, num2cell(1:4), 'UniformOutput', false);
strcat('Syl_', c1)
ans =
1×4 cell array
{'Syl_1'} {'Syl_2'} {'Syl_3'} {'Syl_4'}

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by