Reputation: 6668
I am trying to append a number to a cell string ('fract') the code is below. After executing the code though all the cells in fract_lbl are still just 'fract'.
fract_lbl = repmat({'fract'}, int_fract, 1);
num_vec = [1:int_fract]';
fract_lbl = strcat(fract_lbl, num2cell(num_vec));
How can I append a number to a cell string?
Upvotes: 0
Views: 224
Reputation: 19689
With ≥ R2016b, you can skip repmat
and concatenate strings directly with plus
as follows:
Str = 'fract' + string(numvec);
Implicit expansion is happening in above line.
The above line gives a string array. In your question, you actually have a cell array containing characters in each cell, not strings. If you need a cell array of characters then you can further use cellstr
as follows:
Str = cellstr(Str);
Upvotes: 1