How to create a list of number separated by commas (not a .csv list)?

3 ビュー (過去 30 日間)
NiallH
NiallH 2015 年 11 月 11 日
コメント済み: Star Strider 2015 年 11 月 11 日
I am looking to create a list held in a variable like the following:
1,2,3,4
I am currently using this instead:
a = linspace(1,number_of_lines,number_of_lines)
a = mat2str(a);
But this gives:
[1 2 3 4]
in a 1x9 size box filled with those characters, not:
1,2,3,4
I am re-typing the numbers in separated with commas when the relevant dialogue box appears. For large lists, this is not feasible.
How would I do this automatically?

採用された回答

Star Strider
Star Strider 2015 年 11 月 11 日
One approach:
number_of_lines = 4;
a = linspace(1,number_of_lines,number_of_lines);
a_commas = [sprintf('%.0f,',a(1:end-1)) sprintf('%.0f',a(end))]
a_commas =
1,2,3,4
Although by definition, a cell array is a comma-separated list.
  2 件のコメント
NiallH
NiallH 2015 年 11 月 11 日
I tried this earlier today, could not get it to work! (Maybe typed it wrong)
Many thanks ,exactly what was needed
Star Strider
Star Strider 2015 年 11 月 11 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by