n = 101;
u = 51; % offset for indexing
v = zeros(1,n)
v(u + (-50:-10)) = -10
v(u + (-10:10)) = (-10):10
v(u + (10:50)) = 10
I = repmat(v, n, 1); % replicate v, n times vertically, once horizontally
imshow((I+ 10) / 20); % matlab expects image values to range from 0 to 1!
Note that I've used 101 places in the vector $v$ so that my indexing and your formula match nicely. There are also no loops in this program, which will make it much more efficient than matlab code with loops (or at least that's a general principle to live by; in this case, the code's so short it's probably moot.)
Here's an alternative, more "matlab-esque" version
n = 101;
v = zeros(1,n)
v1 = -10 * ones(n, 40);
v2 = repmat(-10:10, n, 1);
v3 = 10 * ones(n, 40);
I = [v1, v2, v3];
imshow((I+ 10) / 20); % matlab expects image values to range from 0 to 1!
figure(gcf); % bring the figure to the foreground
And here's one last version, in a rather terser matlab style:
n = 101;
I = min(10, max(-10, repmat(-50:50, 101, 1)));
imshow((I+ 10) / 20); % matlab expects image values to range from 0 to 1!
figure(gcf); % bring the figure to the foreground