Here's one easy, straightforward way:
A=[2, 3, 4, 2, 2, 3, 7, 3, 3] % size 10x1 could be 10e5x1
% out is the sign of the difference
out = sign(diff(A))
% Fill in zeros with the last known good sign
for k = 2 : length(out)
if out(k) == 0
out(k) = out(k-1);
end
end
% Print to command window
out
The only requirement is that you don't start off with one or more zeros because there is no prior sign to use for "out" in that case.