matlab - Three draggable points on a plot -


i trying create callback function(s) following:

  1. a user clicks on line
  2. each click results in small circle snapped nearest data point
  3. as new data point (a new circle) selected, line created between 2 points (eventually, total of 2 lines between 3 points)
  4. when third data point selected, text box appear calculation based on 3 sets of xy coordinates
  5. as user drags around of 3 points, calculation in text box updated
  6. i'd have many sets of 3 points , associated text box want on different sections of curve

i think have use "impoint" generate draggable points , use "bsxfun" snapping. have in similar context uses "imline" , functions provided below if it's of help.

function calc_slope(handle,event)  axis_h = findobj(gcf,'type','axes');    line = get(gco);  xdata = line.xdata; ydata = line.ydata;  tb_h = text(0,0,'');  fcn_constr = @(pos) imline_snap(pos, [xdata(:) ydata(:)],tb_h);   imline_h = imline(axis_h, 'positionconstraintfcn', fcn_constr);  addlistener(imline_h, 'objectbeingdestroyed', @(obj,event) delete(tb_h));  function constr_pos = imline_snap(new_pos, positions, tb_h)  [~, ind1] = min(sum(bsxfun(@minus, new_pos(1,:), positions).^2, 2)); [~, ind2] = min(sum(bsxfun(@minus, new_pos(2,:), positions).^2, 2));  constr_pos = [positions(ind1,:); positions(ind2,:)];      set(tb_h, 'string',...               sprintf(['    \\deltay/\\deltax = ',...                        num2str((constr_pos(2,2)-constr_pos(1,2))/(constr_pos(2,1)-constr_pos(1,1))),...                        '\n    \\deltax = ',num2str(constr_pos(2,1)-constr_pos(1,1)),...                        ', \\deltay = ',num2str(constr_pos(2,2)-constr_pos(1,2))]),...               'position', mean(constr_pos)); 

the core functions written @luis mendo , can't understand how these work: credits him. can modify script or create scratch accomplish problem described above?

i resorted using datacursormode , getcursorinfo. no lines or automatic updating, points snapped , draggable.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -