MATLAB Answers

Create cell array of numbers

11 views (last 30 days)
how can i create a function that creates a cell array of number array 1:n, so the result is a cell array of string values.
so for example if i call that function s=f(1:10), it give me:
s = {'1','2','3','4','5','6','7','8','9','10'}
thanks so much!


Sign in to comment.

Accepted Answer

Guillaume on 16 Dec 2019
Edited: Guillaume on 16 Dec 2019
This is dead easy if you are happy using the newish string type instead of char vectors:
s = string(1:10)
You can convert that to a cell array of char vectors, but you may as well continue using strings as they're easier to work with.
s = cellstr(string(1:10)) %if a cell array of char vector is really desired

  1 Comment

Steven Niggebrugge
Steven Niggebrugge on 19 Dec 2019
super, thanks!
this was by far the easiest and most effective solution.

Sign in to comment.

More Answers (0)

Sign in to answer this question.