GUI中的Matlab缩放侦听器 [英] Matlab zoom listener in a GUI
问题描述
我有一个GUI,它由一个图和一个MATLAB中的静态文本组成.
I have a gui that consists of a plot and a static text in MATLAB.
我想在图上使用一个缩放侦听器,以便可以使用放大倍数更新静态文本.无论如何,我能做到这一点吗?
I want to have a zoom listener on the plot so that i can update the static text with the magnification. Is there anyway that i can do this?
推荐答案
脚本文件(或者,您可以根据自己的喜好将其作为嵌套函数来实现):
Script file (or you can do this as a nested function, whatever you feel like):
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
文件:
function testcallback(obj,event_obj,t)
xlim = get(event_obj.Axes,'XLim');
set(t,'fontsize',4000/(xlim(2)-xlim(1)));
end
输出:
此外,如果您想直接更改缩放功能的工作方式或使其他事情陷入混乱,这是zoom
对象的matlab文档:
Also, here's the matlab documentation on the zoom
object if you want to change directly how the zoom function works or mess with some other things:
http://www.mathworks.com/help/matlab/ref /zoom.html
最后,您可以将其实现为嵌套函数以传递文本对象.将其另存为testfunction.m
,然后只需键入testfunction
,即可在终端中运行它:
Lastly, you can implement this as a nested function to pass the text object. Save this as testfunction.m
and then run it in the terminal by simply typing 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
这篇关于GUI中的Matlab缩放侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!