calculating and displaying the slope of a line
3 views (last 30 days)
Show older comments
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, the example outputs the position data in the title of a figure using the 'title' command.
Is there a way to output this in a text box using the 'text' command?
I want to display the slope next to the line drawn.
Also, it will be great if the text box also gets deleted together with the associated line.
Please, help.
Thank you,
Eric
0 Comments
Answers (2)
Purushottama Rao
on 3 Sep 2015
Edited: Stephen23
on 8 Sep 2015
You can try uicontrol. Change the position coordinates according to your requirement. The same thing can be expanded for delta x and delta y as well.
uicontrol('Style','text','String',num2str(num2str((xy(4)-xy(3))/(xy(2)-xy(1)))),'Position',[120 350 300 25],'Fontsize',18);
Image Analyst
on 3 Sep 2015
Use sprintf() to create your string, then use text() to place it wherever you want.
2 Comments
Image Analyst
on 7 Sep 2015
"It deletes all other text boxes" <-- then why do you call delete at all?
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!