Interactive plot using impoint
显示 更早的评论
I'm working on developing an application that places a sinusoid over an image due to points selected on the image. I have that part down, but I would like for the user to have the ability of changing( thus updating) the period and amplitude of the sinusoid by moving the points on the image. After the sine function is drawn over the image, I attempt to move a point to update but I receive the following error: "Undefined function 'getPosition' for input arguments of type 'double'." My code is below
function imageDemo2
clf, clc;
hFigure = figure(1);
hAx = axes;
readPic = imread('SomeImage.jpg');
[numRows numCols RGB] = size(readPic);
imagesc(readPic);
hold on;
[x,y] = ginput(2);
hLine = line(x,y,'LineWidth',2,'Color',[0 0 0]);
P1 = impoint(gca,[]);
setColor(P1,'r');
P2 = impoint(gca,[]);
setColor(P2,'r');
P3 = impoint(gca,[]);
setColor(P3,'r');
P4 = impoint(gca,[]);
setColor(P4,'r');
[L1,L2,D1,D2] = dragLine2(P1,P2,P3,P4);
x = L1:L2;
D = floor(D1(:,2) - D2(:,2));
L = 2*floor(L2(:,1)-L1(:,1));
y = (D).*sin((4*pi).*(x-L1(:,1))/L) + L1(:,2);
hplot = plot(x,y,'r','LineWidth',1);
addNewPositionCallback(P1,@dragLine2);
addNewPositionCallback(P2,@dragLine2);
addNewPositionCallback(P3,@dragLine2);
addNewPositionCallback(P4,@dragLine2);
function [L1,L2,D1,D2] = dragLine2(P1,P2,P3,P4)
L1 = getPosition(P1);
L2 = getPosition(P2);
D1 = getPosition(P3);
D2 = getPosition(P4);
I did try to make P1-P4 global variables but I encountered the same problems. If there is any guidance you can provide towards a mistake I made or something I neglected to add, your help would be greatly appreciated.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!