In addition to the square() function (requires signal processing toolbox) and the heaviside() function (symbolic math toolbox), here's a much lower level, custom function that produces one step as is depicted in your image.
stepFunc = @(x, start, width, height, base) ...
[zeros(1,sum(x < start)), 0, ones(1, sum(x >= start & x <= start+width)), 0, zeros(1, sum(x > start+width))] ...
* height + base;
x = 0:1000;
start = 200;
width = 250;
height = 4;
base = 1.0;
y = stepFunc(x, start, width, height, base);
stepIdx = find(abs(diff(y)) == abs(height));
xIdx = [1:stepIdx(1), stepIdx(1):stepIdx(2)-1, stepIdx(2)-1:length(x)];
newX = x(xIdx);
figure
plot(newX, y)
ylim(ylim + [-1.1, 1.1]*range(ylim))
Best Answer