create vector x from 0 to l with m constant spacing in matlab

main.m
% matlab, vector, constant spacing, linspace, array indexing
% To create a vector x with m constant spacing from 0 to l in MATLAB, you can use the "linspace" function as follows:
l = 10; % end point
m = 5; % number of points
x = linspace(0, l, m); % create a vector with m points, evenly spaced between 0 and l

% Alternatively, you can create the vector x using array indexing as follows:
delta = l / (m - 1); % calculate the constant spacing between the points
x = 0:delta:l; % create a vector with m points, evenly spaced between 0 and l
541 chars
10 lines

In either case, the resulting vector x will have m points, with constant spacing between each point.

gistlibby LogSnag