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

조회 수: 3 (최근 30일)
Fredrik
Fredrik 2014년 2월 28일
댓글: Fredrik 2014년 3월 3일
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에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by