English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

MATLAB has vectors with evenly spaced elements

MATLAB allows you to create vectors with uniformly spaced elements.

To create a vector v with the first element f, the last element l, and the difference between elements as any real number n, it is written as:

v = [f : n : l]

Online Example

Create a script file using the following code-

v = [1: 2: 20];
sqv = v.^2;
disp(v);
disp(sqv);

When running the file, it displays the following result-

1    3    5    7    9   11   13   15   17   19
   1     9    25    49    81   121   169   225   289   361