简体   繁体   English

当我在代码中使用inputdlg时,如何放大图形?

[英]How to zoom in on figures when I use inputdlg in my code?

First, when I use inputdlg , Matlab does not let me to zoom in on my figure. 首先,当我使用inputdlg时 ,Matlab不允许我放大我的身材。

Second, when I enter a number using the command and try to convert it to cell using num2cell , I get this error: 'error using cellstr input must be a string'. 其次,当我使用命令输入数字并尝试使用num2cell将其转换为单元格时,出现以下错误:“使用cellstr输入的错误必须是字符串”。

This is the piece of code that I am using: 这是我正在使用的代码:

No = cell2mat(inputdlg('Type in number: '));

(this is where I can't zoom in anymore!) (这是我无法再放大的地方!)

prompt = num2cell(1:2*No);
title = 'Numbers';
answer = inputdlg(prompt,title);

(this is where I get the error!) (这是我得到错误的地方!)

Do you have any ideas how I can resolve these issues? 您有什么想法可以解决这些问题吗? I am using Matlab on a Mac system. 我在Mac系统上使用Matlab。

To programmatically zoom in or zoom out in a figure, you can use the zoom function. 要以编程方式zoom inzoom out图形,可以使用zoom功能。

An example could be: 例如:

% 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)

This will zoom in the plot by the value defined in the inputdlg . 这将按inputdlg定义的值zoom in绘图。

The zoom will be action will be centered in the center of the axes, as it happens when you select the zoom icon in the figure toolbar and click on the centre of the figure. 当您在图形工具栏中选择缩放图标并单击图形的中心时,缩放即动作将在轴的中心居中。

Also, you can simply call 另外,您只需拨打

% Enable zooming
zoom(my_fig,'on')

to enable the zoom, this has the same effect than clicking on the zoom icon on the figure toolbar. 要启用缩放,与单击图形工具栏上的缩放图标具有相同的效果。

If you want to zoom a particular area of the graph, you can change the values of xlim and ylim . 如果要缩放图形的特定区域,可以更改xlimylim的值。

With respect to the plot created in the example, you can use inputdlg to get the new limits and then update the plot 对于在示例中创建的图,您可以使用inputdlg获取新的限制,然后更新图

In this case, you have to input the 4 values in the inputdlg separated by a space (eg 2.5 5.5 5.5 7.5 ) 在这种情况下,必须在输入的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)];

Having stored the original values of the limits, you zoom out setting back them. 存储极限的原始值后,可以缩小设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM