How do I add numbers into a sequence

조회 수: 5 (최근 30일)
Eric Seinen
Eric Seinen 2022년 5월 16일
답변: Image Analyst 2022년 5월 17일
Say I have a matrix [1;10;30] and I wanted a matrix that added 9 data values after each value with an added 1 which would give me [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;30;31;32;33;34;35;36;37;38;39] what code would bring me that answer?

채택된 답변

Jan
Jan 2022년 5월 16일
x = [1;10;30];
y = x.' + (0:9).';
y = y(:)

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 5월 17일
Even simpler, though not as general (but you didn't ask for it to be general)
v = [1:9, 10:19, 30:39]'
v = 29×1
1 2 3 4 5 6 7 8 9 10

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by