[英]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.