calculating and displaying the slope of a line
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Purushottama Rao
2015 年 9 月 3 日
編集済み: Stephen23
2015 年 9 月 8 日
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
2015 年 9 月 3 日
Use sprintf() to create your string, then use text() to place it wherever you want.
2 件のコメント
Image Analyst
2015 年 9 月 7 日
"It deletes all other text boxes" <-- then why do you call delete at all?
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!