How can I have a starting number, a step size, then the number of numbers I need in a 1D array?
42 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
James
am 2 Sep. 2019
Beantwortet: Giulia Paioletti
am 9 Jan. 2021
I know the colon operator gives the starting number: step size: final number, but is there an operator with the starting number, step size and the number of numbers you want in that array
eg. >> frameList = GenerateFrameList (10,20,4)
frameList = 10 30 50 70
eg. >> frameValues = GenerateFrameList (20,1,5)
frameValues = 20 21 22 23 24
0 Kommentare
Akzeptierte Antwort
Stephen23
am 2 Sep. 2019
Bearbeitet: Stephen23
am 2 Sep. 2019
>> A = 5; % starting number
>> S = 3; % step
>> N = 12; % number of values
>> V = A+S*(0:N-1)
V =
5 8 11 14 17 20 23 26 29 32 35 38
You can put it into a function if you want to:
>> GenerateFrameList = @(A,S,N) A+S*(0:N-1);
>> GenerateFrameList(1,4,3)
ans =
1 5 9
>> GenerateFrameList(10,20,4)
ans =
10 30 50 70
>> GenerateFrameList(20,1,5)
ans =
20 21 22 23 24
0 Kommentare
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!