Here is my answer.
8 CommentsOldest to Newest
%% Some Data x = linspace(0, 2*pi)'; y = sin(x); plot(x, y); % a basic monochrome plot %% Trick surface into a 2-D plot surface('XData', [x x], ... % N.B. XYZC Data must have at least 2 cols 'YData', [y y], ... 'ZData', zeros(numel(x),2), ... 'CData', [y y], ... 'FaceColor', 'none', ... 'EdgeColor', 'interp', ... 'Marker', 'none');
Thank you. I have looked for something like your surface trick for a long time. That works well, is fast and tolerates NaNs in the Cdata. For a case with N points and N-1 segments between them, I modified it to, e.g., [x(1:(end - 1)) x(2:end)] for Xdata, which also works.