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 Center および File ExchangeCreating, 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