How can I generate a comma separated list from the MATLAB vector s = [1, 2, 3, 4]?

3 ビュー (過去 30 日間)
William Doak
William Doak 2022 年 1 月 26 日
回答済み: Walter Roberson 2022 年 1 月 27 日
In Maple I can do the following:
s := <1, 2, 3, 4>
seq(s[i], i = 1 .. 4)
1, 2, 3, 4
How can I generate a comma separated list from the MATLAB vector s = [1, 2, 3, 4]?

回答 (2 件)

Benjamin Thompson
Benjamin Thompson 2022 年 1 月 26 日
>> s = 1:4
s =
1 2 3 4
>> stringOut = sprintf("%d,", s)
stringOut =
"1,2,3,4,"

Walter Roberson
Walter Roberson 2022 年 1 月 27 日
s = 1:4;
ExpandCell = @(C) C{:};
[A,B,C,D] = ExpandCell(num2cell(s))
A = 1
B = 2
C = 3
D = 4

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by