[英]How to zoom in on figures when I use inputdlg in my code?
首先,当我使用inputdlg时 ,Matlab不允许我放大我的身材。
其次,当我使用命令输入数字并尝试使用num2cell将其转换为单元格时,出现以下错误:“使用cellstr输入的错误必须是字符串”。
这是我正在使用的代码:
No = cell2mat(inputdlg('Type in number: '));
(这是我无法再放大的地方!)
prompt = num2cell(1:2*No);
title = 'Numbers';
answer = inputdlg(prompt,title);
(这是我得到错误的地方!)
您有什么想法可以解决这些问题吗? 我在Mac系统上使用Matlab。
要以编程方式zoom in
或zoom out
图形,可以使用zoom
功能。
例如:
% Create a Figure
my_fig=figure
% Plot something in the figure
plot(randi(10,10,1))
grid minor
% Get the zoom factor
zoom_factor=str2double(inputdlg('Type in number: '))
% Zoom the axes of the selected factor
zoom(my_fig,zoom_factor)
这将按inputdlg
定义的值zoom in
绘图。
当您在图形工具栏中选择缩放图标并单击图形的中心时,缩放即动作将在轴的中心居中。
另外,您只需拨打
% Enable zooming
zoom(my_fig,'on')
要启用缩放,与单击图形工具栏上的缩放图标具有相同的效果。
如果要缩放图形的特定区域,可以更改xlim
和ylim
的值。
对于在示例中创建的图,您可以使用inputdlg
获取新的限制,然后更新图
在这种情况下,必须在输入的lg中输入4个值,并用空格隔开(例如2.5 5.5 5.5 7.5
)
% Get the axes handle
ax=gca;
% Store the original X anf Y Limit
orig_xlim=ax.XLim;
orig_ylim=ax.YLim;
zoom_factor=inputdlg('Type in new lim: ')
new_lim=str2num(char(zoom_factor))
ax.XLim=[new_lim(1) new_lim(2)];
ax.YLim=[new_lim(3) new_lim(4)];
存储极限的原始值后,可以缩小设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.