脚本文件(或者您可以将其作为嵌套函数执行,无论您喜欢什么):
f = figure(1);
z = zoom(f);
imshow(ones(400));
xlim = get(gca,'XLim');
t = text(150,150,'hello','fontsize',4000/(xlim(2)-xlim(1)));
set(z,'ActionPostCallback',@(obj,event_obj)testcallback(obj,event_obj,t));
功能testcallback.m
file:
function testcallback(obj,event_obj,t)
xlim = get(event_obj.Axes,'XLim');
set(t,'fontsize',4000/(xlim(2)-xlim(1)));
end
Output:
另外,这是有关的 matlab 文档zoom
如果您想直接更改缩放功能的工作方式或与其他一些事情混淆,请使用 object:
http://www.mathworks.com/help/matlab/ref/zoom.html http://www.mathworks.com/help/matlab/ref/zoom.html
EDIT:最后,您可以将其实现为嵌套函数来传递文本对象。将此另存为testfunction.m
然后只需在终端中输入即可运行它testfunction
:
function testfunction
f = figure(1);
z = zoom(f);
imshow(ones(400));
xlim = get(gca,'XLim');
t = text(150,150,'hello','fontsize',4000/(xlim(2)-xlim(1)));
set(z,'ActionPostCallback',@testcallback);
function testcallback(obj,event_obj)
xlim = get(event_obj.Axes,'XLim');
set(t,'fontsize',4000/(xlim(2)-xlim(1)));
end
end