function h = cursorLine(x,y,innerThickness, outerThickness) if nargin == 2 innerThickness = 2; outerThickness = 4; end h.thick = line(x,y); h.thin = line(x,y); set(h.thick, 'color', [1 1 1]); set(h.thin , 'color', [0 0 0]); set(h.thick, 'linewidth', outerThickness); set(h.thin , 'linewidth', innerThickness);
5 CommentsOldest to Newest
This is a nice tip. Thank you. I especially like that you made the code available outside the video. Now I can see the tip at a glance.
I think it would be more useful to have two lines sharing a common thickness (which the user could adjust) and use different lifestyles. One line would be solid, the other dashed.
That is the great thing here. You have the code, give it a try!
Thanks for the share, Doug
Just did small tweaks and added some comments. Just wanted to have your suggestions too…
function cursorLine(x,y,innerThickness, outerThickness)
% Making a line visible over an image in MATLAB
% x : X axis co-ordinates of the points on the line
% y : Y axis co-ordinates of the points on the line
% innerThickness : Thickness of the black line (inner line)
% outerThickness : Thickness of the white line (outer line)
% Setting default values if no. of inputs are less than specified
if nargin == 2
innerThickness = 2;
outerThickness = 4;
if nargin innerThickness
h.thick = line(x,y);
set(h.thick, ‘color’, [1 1 1]);
set(h.thick, ‘linewidth’, outerThickness);
% Display black line only if inner line width is more than zero
if innerThickness > 0
h.thin = line(x,y);
set(h.thin , ‘color’, [0 0 0]);
set(h.thin , ‘linewidth’, innerThickness);
Look like good changes to me.