MATLAB: Can I create a line with hashes on one side in MATLAB 7.8 (R2009a)

MATLAB

I would like to use a line style which shows hashes on one side of a line, in order to plot constraints on a design space plot.

Best Answer

The ability to plot lines with such hashes does not exist in MATLAB 7.8 (R2009a).
As a workaround, the code below illustrates how you can manually create the hashes by plotting lines which are perpendicular to the curve at each data point.
clear all; close all;
figure;
ax = gca;
dx = 0.2;
length = 0.5;
x = -10:dx:10;
y = x.^3;
plot(ax, x, y, 'r')
ratio = get(ax, 'DataAspectRatio');
scaleyx = ratio(2)/ratio(1);
dy = gradient(y);
dy = dy/scaleyx; %Put y and x on same scale
theta = atan(dy./dx);
newx = x+length*sin(-theta);
newy = y+length*cos(-theta)*scaleyx;
hold on;
plot([x; newx], [y; newy], 'b')