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

3 vues (au cours des 30 derniers jours)
William Doak
William Doak le 26 Jan 2022
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]?

Réponses (2)

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

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

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by