Slope calculation on a curve

2 ビュー (過去 30 日間)
Eric Hong
Eric Hong 2015 年 8 月 26 日
編集済み: Csaba 2016 年 4 月 1 日
I create a figure with toggle button on its toolbar by uitoggletool. The callback function for it is shown below:
function calc_slope(handle,event)
on = get(handle,'State');
if strcmpi(on,'on') || strcmpi(on,'off'),
title(['\DeltaY/\DeltaX = ',num2str((xy(4)-xy(3))/(xy(2)-xy(1))),...
' [\DeltaX = ',num2str(xy(2)-xy(1)),', \DeltaY = ',num2str((xy(4)-xy(3))),']']));
As you can see, I'm trying to calculate the slope between two points on a curve. The code is something I found in the web that's pretty close to what I'm trying to. The 'addNewPositionCallback" is executed in both 'On' and 'Off' state, but it's merely a means to repeat the process as many times as a user wants. What I really want to do is number 4 and 5 below.
What I really want to do is as follows:
  1. "Draggable" points "snapped" to the nearest curve
  2. The connecting line shows
  3. Delta X, delta Y, and the slope provided in a "text box" drawn near the curve
  4. Draw as many lines as needed while in the 'On' state
  5. Delete all lines and 'text' boxes when toggle button is set to 'Off'
The imline function gives a bunch of features such as different line colors. I can care less on those. The major "wants" are the snapping and the text box.
Your help will be greatly appreciated.
Thank you,

回答 (1 件)

Csaba 2016 年 4 月 1 日
編集済み: Csaba 2016 年 4 月 1 日
I have very-very similar problem. In addition I want the lines stay there and if someone moves the endpoits it should recalculate the slope ( addNewPositionCallback will calculate the slope chillion of times if movement of the endpoints are remarkable). Also there is no "addDeleteCallback function to do something if someone deletes the line by mouse.
However, I can answer to points 4. and 5.
There are callback functions for uitoggletool. There is an OffCallback and an OnCallback. I have found them on the GUITOOL "Toolbar editor". You can make these two functions and do whatever you want there.


Help Center および File ExchangeAxis Labels についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by