资源简介
当MATLAB中运行出来的图细节不够明显时,可以采用该函数进行局部放大,只需把该函数复制到对应的文件里,然后再命令行窗口输入magnify指令即可
代码片段和文件信息
function magnify(f1)
%
%magnify(f1)
%
% Figure creates a magnification box when under the mouse
% position when a button is pressed. Press ‘+‘/‘-‘ while
% button pressed to increase/decrease magnification. Press
% ‘>‘/‘<‘ while button pressed to increase/decrease box size.
% Hold ‘Ctrl‘ while clicking to leave magnification on figure.
%
% Example:
% plot(1:100randn(1100)(1:300)/3rand(1300)) grid on
% magnify;
% Rick Hindman - 7/29/04
if (nargin == 0) f1 = gcf; end;
set(f1 ...
‘WindowButtonDownFcn‘ @ButtonDownCallback ...
‘WindowButtonUpFcn‘ @ButtonUpCallback ...
‘WindowButtonMotionFcn‘ @ButtonMotionCallback ...
‘KeyPressFcn‘ @KeyPressCallback);
return;
function ButtonDownCallback(srceventdata)
f1 = src;
a1 = get(f1‘CurrentAxes‘);
a2 = copyobj(a1f1);
set(f1 ...
‘UserData‘[f1a1a2] ...
‘Pointer‘‘fullcrosshair‘ ...
‘CurrentAxes‘a2);
set(a2 ...
‘UserData‘[20.2] ... %magnification frame size
‘Color‘get(a1‘Color‘) ...
‘Box‘‘on‘);
xlabel(‘‘); ylabel(‘‘); zlabel(‘‘); title(‘‘);
set(get(a2‘Children‘) ...
‘LineWidth‘ 2);
set(a1 ...
‘Color‘get(a1‘Color‘)*0.95);
set(f1 ...
‘CurrentAxes‘a1);
ButtonMotionCallback(src);
return;
function ButtonUpCallback(srceventdata)
H = get(src‘UserData‘);
f1 = H(1); a1 = H(2); a2 = H(3);
set(a1 ...
‘Color‘get(a2‘Color‘));
set(f1 ...
‘UserData‘[] ...
‘Pointer‘‘arrow‘ ...
‘CurrentAxes‘a1);
if ~strcmp(get(f1‘SelectionType‘)‘alt‘)
delete(a2);
end;
return;
function ButtonMotionCallback(srceventdata)
H = get(src‘UserData‘);
if ~isempty(H)
f1 = H(1); a1 = H(2); a2 = H(3);
a2_param = get(a2‘UserData‘);
f_pos = get(f1‘Position‘);
a1_pos = get(a1‘Position‘);
[f_cp a1_cp] = pointer2d(f1a1);
set(a2‘Position‘[(f_cp./f_pos(3:4)) 0 0]+a2_param(2)*a1_pos(3)*[-1 -1 2 2]);
a2_pos = get(a2‘Position‘);
set(a2‘XLim‘a1_cp(1)+(1/a2_param(1))*(a2_pos(3)/a1_pos(3))*diff(get(a1‘XLim‘))*[-0.5 0.5]);
set(a2‘YLim‘a1_cp(2)+(1/a2_param(1))*(a2_pos(4)/a1_pos(4))*diff(get(a1‘YLim‘))*[-0.5 0.5]);
end;
return;
function KeyPressCallback(srceventdata)
H = get(gcf‘UserData‘);
if ~isempty(H)
f1 = H(1); a1 = H(2); a2 = H(3);
a2_param = get(a2‘UserData‘);
if (strcmp(get(f1‘CurrentCharacter‘)‘+‘) | strcmp(get(f1‘CurrentCharacter‘)‘=‘))
a2_param(1) = a2_param(1)*1.2;
elseif (strcmp(get(f1‘CurrentCharacter‘)‘-‘) | strcmp(get(f1‘CurrentCharacter‘)‘_‘))
a2_param(1) = a2_param(1)/1.2;
elseif (strcmp(get(f1‘CurrentCharacter‘)‘<‘) | strcmp(get(f1‘CurrentCharacter‘)‘‘))
a2_param(2) = a2_param(2)/1.2;
elseif (strcmp(get(f1‘CurrentCharacter‘)‘>‘) | strcmp(get(f1‘CurrentCharacter‘)‘.‘))
a2_param
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1312 2016-05-11 17:36 局部放大函数\magnify\license.txt
文件 4227 2016-05-11 17:36 局部放大函数\magnify\magnify.m
文件 234286 2015-04-29 21:49 局部放大函数\局部放大函数\1.bmp
文件 699678 2015-04-29 21:49 局部放大函数\局部放大函数\2.bmp
文件 646 2015-08-15 16:43 局部放大函数\局部放大函数\go_prepare_image.m
文件 335 2015-08-15 15:45 局部放大函数\局部放大函数\local_magnify.m
文件 1115 2015-08-15 16:44 局部放大函数\局部放大函数\nouse_local_magnify.m
目录 0 2018-12-22 09:38 局部放大函数\magnify
目录 0 2015-08-15 16:40 局部放大函数\局部放大函数
目录 0 2018-12-22 09:38 局部放大函数
----------- --------- ---------- ----- ----
941599 10
- 上一篇:基于粒子群算法的PID控制器优化设计
- 下一篇:gui_mainfcn.m
评论
共有 条评论