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

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by