📄 cursor.m
字号:
%
% CURSOR is used to read the position (x, y coordinates) on the
% current plot using the cursor facility provided in Matlab.
% Also, for frequency responses, the frequency corresponding
% to the smallest error can be found. For root locus, the corres-
% ponding gain K can also be found. Error messages are usually
% given when the selected point is far from the locus on the plot.
%
% Author: Ole Barup Sorensen, Rapid Data Ltd
% Copyright (c) 1989-94 by Rapid Data Ltd
% Revision 10:34 07/02/94
[x_pos,y_pos,key] = getpt(gcf,choice,ip,an_type);
Ax_x = get(gca,'Xlim');
Ax_y = get(gca,'Ylim');
Ax_rx = Ax_x(2)-Ax_x(1);
Ax_ry = Ax_y(2)-Ax_y(1);
xmin =2;
scale = 100;
if an_type == 1,
[xmin,ii] = min(abs(w_range-x_pos*ones(size(w_range))));
if (choice == 2)|(key == 1),
v = abs(mmm0(ii,:)-y_pos)/Ax_ry;
elseif (choice == 3)|(key == 2),
v = abs(ddd(ii,:)-y_pos)/Ax_ry;
else
v = abs(mmm0(ii,:)-y_pos)/Ax_ry;
end
[xmin,i] = min(v); xmin=xmin*100;
if xmin < 1.5,
ic = 1; wm = w_range(ii); mm = mmm0(ii,i);
pm = ddd(ii,i);
end
elseif ((an_type == 2 & ip == 1 )| an_type == 3),
[xmin,ii] = min(abs((mmm-x_pos*ones(size(mmm)))/Ax_rx)+ ...
abs((ddd-y_pos*ones(size(ddd)))/Ax_ry));
[xmin,ij] = min(xmin); xmin = scale*xmin;
elseif (an_type == 2 & ip ~= 1),
db=1;
szmmm=size(mmm);
vv = abs((mmm-x_pos*ones(size(md1)))/Ax_rx)+ ...
abs((ddd-y_pos*ones(size(pd1)))/Ax_ry);
[xmin,ii] = min([vv; abs((md1-x_pos*ones(size(md1)))/Ax_rx)+ ...
abs((pd1-y_pos*ones(size(pd1)))/Ax_ry)]);
[xmin,ij] = min(xmin); xmin = scale*xmin;
if ii(ij) > szmmm(1), ii(ij)=ii(ij)-szmmm(1); db=2;end;
elseif an_type == 4,
[xmin,ii] = min(abs((ddd-x_pos*ones(size(ddd)))/Ax_rx)+ ...
abs((mmm-y_pos*ones(size(mmm)))/Ax_ry));
[xmin,ij] = min(xmin); xmin = scale*xmin;
elseif an_type == 5,
mm0 = mmm; i1 = size(mm0);
if id>9,
mm0 = [mm0 ddd];
% i2 = size(ddd);
end
vv = abs((real(mm0)-x_pos*ones(size(mm0)))/Ax_rx);
vv = vv+abs((imag(mm0)-y_pos*ones(size(mm0)))/Ax_ry);
[xmin,ii] = min(vv);
[xmin,ij] = min(xmin); xmin = scale*xmin;
elseif (an_type == 6 | an_type == 7),
[xmin,ii] = min(abs(t_range-x_pos*ones(size(t_range))));
var = mmm0(ii,:); i0 = size(var);
for i = 1:i0(2),
v(i) = abs((var(i)-y_pos)/Ax_ry);
[xmin, ij] = min(v); xmin = xmin*scale;
end
end
set(Han_b2(4:6),'String',' ');
if xmin < 1.5,
ic = 1;
hold on
plot(x_pos,y_pos,'o')
hold off
else
ic = 0;
end
if an_type < 6,
if an_type == 5
wm = k_range(ii(ij));
elseif an_type ~= 1,
wm = w_range(ii(ij));
if an_type == 2,
pm = atan2(ddd(ii(ij),ij),mmm(ii(ij),ij))*180/pi;
if ip == 1,
mm = 10*log10(mmm(ii(ij),ij)^2+ddd(ii(ij),ij)^2);
elseif ip==2,
mm = tan(pi*x_pos*0.5/cos(pm*pi/180));
else
if db == 1,
mm = 10*log10(mmm(ii(ij),ij)^2+ddd(ii(ij),ij)^2);
else
mm = tan(pi*x_pos*0.5/cos(pm*pi/180));
end
clear db szmmm
end
elseif an_type == 3,
mm = -10*log10(mmm(ii(ij),ij)^2+ddd(ii(ij),ij)^2);
pm = 180-atan(ddd(ii(ij),ij)/mmm(ii(ij),ij))*180/pi;
elseif an_type == 4,
mm = mmm(ii(ij),ij); pm = ddd(ii(ij),ij);
end
end
if (an_type >= 1) & (an_type <= 4),
if (ic == 0),
set(Han_b2(4),'String','Sorry, the selected point is NOT')
set(Han_b2(5),'String','on the locus ')
else
set(Han_b2(4),'String',['The frequency w = ' num2str(wm) ' rad/sec'])
set(Han_b2(5),'String',['The magnitude m = ' num2str(mm) ' dB'])
set(Han_b2(6),'String',['The phase ph = ' num2str(pm) ' degrees'])
clear wm mm pm
end
elseif an_type == 5
if (ic == 0),
set(Han_b2(4),'String','Sorry, the selected point is NOT')
set(Han_b2(5),'String','on the locus ')
else
set(Han_b2(4),'String',['The corresponding gain = ', num2str(wm) ])
clear wm
end
end
elseif an_type == 6,
if (ic == 0),
set(Han_b2(4),'String','Sorry, the selected point is NOT')
set(Han_b2(5),'String','on the locus ')
else
set(Han_b2(4),'String',[' The time is ' num2str(t_range(ii)) ' Sec' ])
set(Han_b2(5),'String',[' The output ' num2str(mmm0(ii,ij)) ])
clear ii ij
end
elseif (an_type == 7),
if (ic == 0),
set(Han_b2(4),'String','Sorry, the selected point is NOT')
set(Han_b2(5),'String','on the locus ')
else
set(Han_b2(4),'String',[' The time is ' num2str(t_range(ii)) ' Sec' ])
set(Han_b2(5),'String',[' The output ' num2str(mmm0(ii,ij)) ])
clear ii ij
end
end
clear icursor
set(0,'Currentfigure',Fig6);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -