Create cell array of numbers

조회 수: 42 (최근 30일)
Steven Niggebrugge
Steven Niggebrugge 2019년 12월 16일
댓글: Fatemeh Sadeghihassanabadi 2021년 4월 30일
Hi,
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!

채택된 답변

Guillaume
Guillaume 2019년 12월 16일
편집: Guillaume 2019년 12월 16일
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
  댓글 수: 2
Steven Niggebrugge
Steven Niggebrugge 2019년 12월 19일
super, thanks!
this was by far the easiest and most effective solution.
Fatemeh Sadeghihassanabadi
Fatemeh Sadeghihassanabadi 2021년 4월 30일
great answer! solved my problem as well, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by