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

1 view (last 30 days)
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]?

Answers (2)

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

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

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!