Reputation: 43
I have always used colon operator in MATLAB to create a vector in the following way:
j:i:k => [j, j + i, j + 2i, ..., j + m * i]
but now I need to creat a vector like that:
[i, 2i, 4i, 8i, 16i, ... etc]
How can I do this using the colon operator?
Upvotes: 1
Views: 2050
Reputation: 5014
You have previously defined an arithmetic sequence using some variable i
, i.e.
n = (0:4);
i = 2;
a = i*n;
>> i*n
ans =
0 2 4 6 8
What you are trying to define now is a geometric sequence, or
a = i*2.^n
>> i*2.^n
ans =
2 4 8 16 32
You can also use the above to define complex sequences using the imaginary unit i
instead
a = 1i*2.^n
Upvotes: 1