I trying to plot a function which has millions of points. Therefore it is not possible to plot the function as it would crash my computer. However, the entire plot consists of "elbows" in that more than 1 variable cannot change at a time.
Consider the following matrix
a = [1 2 3 4 4 4 4];
b = [1 1 1 1 2 3 4];
These points make the following figure when using plot(a,b)
However, upon closer inspection, I can reduce my plot vectors down to
a = [1 4 4];
b = [1 1 4];
and get the same plot.
My question is: what is a vectorized way to automatically remove every redundant point. I could easily loop through and search for points to remove but this would be expensive. I have tried using combinations of diff and cumsum to do this to no avail. I only have straight lines and right angles in the plot so I do not have to worry about anything of the form ax+b
