Slope calculation on a curve
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:
- "Draggable" points "snapped" to the nearest curve
- The connecting line shows
- Delta X, delta Y, and the slope provided in a "text box" drawn near the curve
- Draw as many lines as needed while in the 'On' state
- 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
0 commentaires
Réponses (1)
Csaba
le 1 Avr 2016
Modifié(e) : Csaba
le 1 Avr 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
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!