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 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