i want to generate a sequence of n numbers

73 Ansichten (letzte 30 Tage)
Matte Rennerts
Matte Rennerts am 9 Mär. 2020
Beantwortet: Voss am 19 Okt. 2023
How would i generate a secuence of N amount of numbers starting at -4 and going up in steps of 2?
Cheers
  3 Kommentare
Matte Rennerts
Matte Rennerts am 9 Mär. 2020
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 am 9 Mär. 2020
Those sequences work with variables as end values as demonstrated in the answer by Benni.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Benjamin Großmann
Benjamin Großmann am 9 Mär. 2020
Bearbeitet: Benjamin Großmann am 9 Mär. 2020
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];

Weitere Antworten (1)

Voss
Voss am 19 Okt. 2023
start = -4;
increment = 2;
N = 8;
sequence = start + (0:N-1)*increment;

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by