Is there an interactive slope calculator between two moveable markers in a figure?

1 次查看(过去 30 天)
Hi, I was wondering if anyone has created a way of interactively showing the slope between 2 points that one can move around in a figure. Lets say I plot something which is close to linear. Then I want to be able to set two markers, maybe one in the end and one in the beginning which can give me the slope between these two points. Then I want to be able to move these two points around to see the slope at different positions in the figure. This feature exists in many measurement programs and I would be suprised if matlab doesnt have this interactive feature. Any ideas?
Thanks, Fredrik Lindelöw
  2 个评论
Fredrik
Fredrik 2014-3-3
Since I haven't received any answers, i did an attempt to create a similar function my self.
% Calculates the slope and offset between two interactively chosen points % in a plot. Then plots the points plus curve and writes out slope and offset in the title of figure. % Can be used to calculate resistance in I-V curves for instance. % Select two points, first point to the left of second point.
function SlopeCalc
X=ginput;
k=(X(2,2)-X(1,2))/(X(2,1)-X(1,1));
m=X(1,2)-X(1,1)*k;
title({'Slope: ',num2str(k),' M value: ',num2str(m)})
plot([X(1,1),X(2,1)],[X(1,1),X(2,1)].*k+m,'ko-')
end
Fredrik
Fredrik 2014-3-3
Using imline made it even better, though slower if many data sets are plotted in same image.
function SlopeCalc2
z=imline
addNewPositionCallback(z,@(z) title(['Slope: ',num2str((z(4)-z(3))/(z(2)-z(1))) ,' M value: ',num2str( z(3)-z(1)*((z(4)-z(3))/(z(2)-z(1))) ) ]));
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by