Convert a numeric vector to 1-D cell of strings

2 ビュー (過去 30 日間)
bethel o
bethel o 2023 年 3 月 31 日
コメント済み: bethel o 2023 年 4 月 4 日
How can one convert a numeric vector to 1-D cell of strings in a in one line without a loop and user defined lamda?
So convert
numbers=[1,2];
to
numbers_dropdown_item={'1','2'}.
A use case is with the accepted value for uidropdown.Items

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 3 月 31 日
nums=[1,2,12,121];
out=cellstr(string(nums))
out = 1×4 cell array
{'1'} {'2'} {'12'} {'121'}
  3 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 3 月 31 日
How is that incorrect? And what is the expected output then?
bethel o
bethel o 2023 年 4 月 4 日
Shouldn't ask the question in the first place had I understood matlab's interesting display.
Apparently: {'1','2'} == {'1'} {'2'} ~= {{'1'}{'2'}} but they are all 1×2 cell array.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by