How can a preserve hyperlinks on figures when saving them for use outside of matlab?

조회 수: 11(최근 30일)
I want to add some hyperlinks to some of the datapoints on my figures. Robert Uhlig helped me out and now I can do it on a figure opened by matlab, using the code written in the answer of this question. This one:
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
hold on
% Create and display the text label
url = '';
labelStr = ['<html><a href="">' 'SPEC' '</a></html>'];
jLabel = javaObjectEDT('javax.swing.JLabel', labelStr);
% Adjust label position
ah = gca;
axesPos = get(ah,'Position');
drawnow(); % necessary to fix the axes positions
Px = round(ah.Position(1) + ah.Position(3)*(2-ah.XLim(1))/(ah.XLim(2)-ah.XLim(1))); % x-position is alway 2
Py = round(ah.Position(2) + ah.Position(4)*(a-ah.YLim(1))/(ah.YLim(2)-ah.YLim(1)));
[hjLabel,hContainer] = javacomponent(jLabel, [Px-30/2,Py+10,30,20], gcf); % center for x, move 5px above y
% Modify the mouse cursor when hovering on the label
% Set the label's tooltip
hjLabel.setToolTipText(['Visit the ' url ' website']);
% Set the mouse-click callback
set(hjLabel, 'MouseClickedCallback', @(h,e)web(['http://' url], '-browser'))
However, I also want to save this figure to be able to use it without running matlab. I have not found a file format yet which preserves the hyperlink in a working condition.
So I would like to be able to save the figure, close matlab, and open the figure independent of matlab, with the working hyperlink on it.
What should I do to achieve this?

채택된 답변

Jan 2017년 9월 22일
You can either export the figure to a HTML file, such that the diagrams appear as graphics and append the link manually. Or A PDF should be working also. But I assume, embedding a link, which is contained in a Java control in a PDF will not work directly.

추가 답변(0개)


Find more on Interactive Control and Callbacks 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!

Translated by