-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_GradientLine.m
More file actions
35 lines (32 loc) · 942 Bytes
/
plot_GradientLine.m
File metadata and controls
35 lines (32 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function plot_GradientLine(x,y,c,varargin)
%% FUNCTION: Plots a line with a gradated color.
% INPUTS: x = x coordinates
% y = y coordinates
% c = colors
% OUTPUTS: N/A
% NOTES: Can pass other variables e.g. {'LineWidth',3}
% ISSUES: N/A
% REFS: http://blogs.mathworks.com/videos/2014/08/12/coloring-a-line-based-on-height-gradient-or-some-other-value-in-matlab/
% AUTHOR: Daniel McNamee, daniel.c.mcnamee@gmail.com
%% otherwise
while ~isempty(varargin)
switch lower(varargin{1})
case 'z'
z = varargin{2};
otherwise
error(['Unexpected option: ' varargin{1}])
end
varargin(1:2) = [];
end
if isempty(z)
z = zeros(1,numel(x));
end
surface('XData',[x; x],...
'YData',[y; y],...
'ZData',[z; z],...
'CData',[c; c],...
'FaceColor','no',...
'EdgeColor','interp',...
'Marker','o',...
varargin{:});
end