Slope calculation on a curve

1 Ansicht (letzte 30 Tage)
Eric Hong
Eric Hong am 26 Aug. 2015
Bearbeitet: Csaba am 1 Apr. 2016
Hi,
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'),
xy=imline;
addNewPositionCallback(xy,@(xy)...
title(['\DeltaY/\DeltaX = ',num2str((xy(4)-xy(3))/(xy(2)-xy(1))),...
' [\DeltaX = ',num2str(xy(2)-xy(1)),', \DeltaY = ',num2str((xy(4)-xy(3))),']']));
end
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,
Eric

Antworten (1)

Csaba
Csaba am 1 Apr. 2016
Bearbeitet: Csaba am 1 Apr. 2016
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.
Csaba

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by