MATLAB Answers

append string to each element in string cell array

616 views (last 30 days)
x_label =
'8' '16' '24' '32' '40'
How can I append ' GHz' to each element in the cell array? Thanks! Can it only be done with a for loop?

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 14 Oct 2011
x_label = {'8' '16' '24' '32' '40'};
strcat(x_label,'GHz')

More Answers (1)

Sean de Wolski
Sean de Wolski on 14 Oct 2011
x_label = { '8' '16' '24' '32' '40'}
x_labelGHz = cellfun(@(c)[c 'GHz'],x_label,'uni',false)
One way
  3 Comments
Sean de Wolski
Sean de Wolski on 14 Oct 2011
And it's not an inline function but a function handle; significantly faster and in current times more common.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!