i want to generate a sequence of n numbers

조회 수: 439 (최근 30일)
Matte Rennerts
Matte Rennerts 2020년 3월 9일
답변: Voss 2023년 10월 19일
How would i generate a secuence of N amount of numbers starting at -4 and going up in steps of 2?
Cheers
  댓글 수: 3
Matte Rennerts
Matte Rennerts 2020년 3월 9일
Those sequence codes work if i have an end value of the secuence but i need the sequence to contain n amount of elements regardless of the last value
Robert U
Robert U 2020년 3월 9일
Those sequences work with variables as end values as demonstrated in the answer by Benni.

댓글을 달려면 로그인하십시오.

채택된 답변

Benjamin Großmann
Benjamin Großmann 2020년 3월 9일
편집: Benjamin Großmann 2020년 3월 9일
You can create sequences with the colon operator (:), for exapmle
v = [4:2:100];
creates v = [4, 6, 8, ... , 100] with values starting at 4, an increment of 2 and stop value 100.
For N numbers starting at -4 and an increment of 2, you have to calculate the stop value:
N = 10;
start_val = -4;
inc = 2;
stop_val = (N-1)*inc + start_val;
v = [start_val:inc:stop_val];

추가 답변 (1개)

Voss
Voss 2023년 10월 19일
start = -4;
increment = 2;
N = 8;
sequence = start + (0:N-1)*increment;

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by