フィルターのクリア

How can I make figure title and annotations selectable?

2 ビュー (過去 30 日間)
Pal Szabo
Pal Szabo 2017 年 9 月 21 日
コメント済み: OCDER 2017 年 9 月 22 日
I have a figures which contains annotations with hyperlinks to other figures. I want the viewer of the figure to be able to just select the hyperlink and copy it to clipboard. How can I do this?

採用された回答

OCDER
OCDER 2017 年 9 月 22 日
編集済み: OCDER 2017 年 9 月 22 日
See the example below. It draws a figure, and if you click above the axes area (where the title is), then it will save the title into your clipboard. You have to use some sort of event-handling function (here copyTitle) and associate this function with the figure WindowButtonUpFcn property as shown below.
plot(1:10, 1:10)
title('Copy this title to clipboard')
set(gcf, 'WindowButtonUpFcn', @copyTitle)
This is the event-handling function:
function copyTitle(hObject, eventdata)
%Remember current units, since you want pixels.
%This is not needed if all units are in pixels, but chances are they're not.
PrevAxUnit = get(gca, 'units');
PrevFigUnit = get(gcf, 'units');
set(gca, 'units', 'pixel');
set(gcf, 'units', 'pixel');
%Determine the figure, axes, point, and pointer-relative-to-figure positions.
AxesPos = get(gca, 'position');
FigurePos = get(gcf, 'position');
PointerPos = get(0, 'pointerlocation');
PointerRelPos = PointerPos - FigurePos(1:2); %1,1 is the bottom left of figure
%Here, add more calculations to determine the exact area of annotation area
%For now, assume any area above axes top is the title area.
if PointerRelPos(2) > sum(AxesPos([2 4]))
TitleStr = get(get(gca, 'title'), 'string');
fprintf('Saving the title "%s" into the clipboard.\n', TitleStr);
clipboard('copy', TitleStr);
%Here, add more actions you want when user clicks the title area
end
%Restore the units back to previous units
set(gca, 'units', PrevAxUnit);
set(gcf, 'units', PrevFigUnit);
  2 件のコメント
Pal Szabo
Pal Szabo 2017 年 9 月 22 日
Thanks much, it works indeed!
OCDER
OCDER 2017 年 9 月 22 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by