?? mfdrag.m
字號:
function [out1, out2] = mfdrag(action,lineHndl,mfType,mfParam)
% MFDRAG Interactive changes of membership functions by clicking and dragging.
% It is called from mfedit.m where action is 'mf' and lineHndl is the current
% selected membership function. MFDRAG allows clicking and dragging of
% membership functions to change their shapes. In general, clicking on a
% membership function curve translates the whole curve; clicking on square
% control points changes the shape.
%
% File name: mfdrag.m
%
% See also DSIGMF, GAUSSMF, GAUSS2MF, GBELLMF, EVALMF, PIMF, PSIGMF,
% SIGMF, SMF, TRAPMF, TRIMF, and ZMF.
% Roger Jang, 6-28-95, Kelly Liu 3-12-97, Rajiv Singh 03/29/2002
% Copyright 1994-2004 The MathWorks, Inc.
% $Revision: 1.19.4.5 $ $Date: 2005/06/27 22:38:43 $
selectColor = [1 0 0];
f = findobj(allchild(0),'type','figure','tag','mfedit');
switch action
case 'mf',
lineH=lineHndl;
set(lineH, 'Color', 'red');
x = get(lineH, 'xdata');
mf_type = mfType;
mf_param = mfParam;
new_mf = evalmf(x, mf_param, mf_type);
set(lineH, 'ydata', new_mf, 'color', 'red');
% setting control points and mouse actions
feval(mfilename, 'set_control_point', lineH, mf_type, mf_param);
case 'get_current_mf',
mf_type = str2mat('trimf', 'trapmf', 'gbellmf', 'gaussmf', 'gauss2mf',...
'sigmf', 'dsigmf', 'psigmf', 'pimf',...
'smf', 'zmf');
mf_type = str2mat(mf_type);
% mf_param_n = [3 4 2 2 3 2 2 4 4 4 4];
which_mf = get(findobj(f, 'tag', 'mftype'), 'value');
out1 = mf_type(which_mf, :);
out2=[];
case 'set_control_point',
% delete all possible previous control points
delete(findobj(f, 'tag', 'leftlow'));
delete(findobj(f, 'tag', 'lefthigh'));
delete(findobj(f, 'tag', 'center'));
delete(findobj(f, 'tag', 'righthigh'));
delete(findobj(f, 'tag', 'rightlow'));
% find MF types and parameters
mf_type = mfType;
mf_param = mfParam;
square = local_get_control_square;
controlcolor='black';
if strcmp(mf_type, 'trimf'),
leftlowH = line(mf_param(1)+real(square), imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
centerH = line(mf_param(2)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'center');
rightlowH = line(mf_param(3)+real(square), imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
elseif strcmp(mf_type, 'trapmf') | strcmp(mf_type, 'pimf'),
leftlowH = line(mf_param(1)+real(square), imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
lefthighH = line(mf_param(2)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'lefthigh');
righthighH = line(mf_param(3)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'righthigh');
rightlowH = line(mf_param(4)+real(square), imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
elseif strcmp(mf_type, 'gaussmf'),
sigma = mf_param(1);
c = mf_param(2);
height = 0.5;
x_left = c - sigma*sqrt(-2*log(height));
x_right = c + sigma*sqrt(-2*log(height));
leftlowH = line(x_left+real(square), height+imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
rightlowH = line(x_right+real(square), height+imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
elseif strcmp(mf_type, 'gauss2mf'),
s1 = mf_param(1); c1 = mf_param(2);
s2 = mf_param(3); c2 = mf_param(4);
height = 0.5;
x_left = c1 - s1*sqrt(-2*log(height));
x_right = c2 + s2*sqrt(-2*log(height));
leftlowH = line(x_left+real(square), height+imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
rightlowH = line(x_right+real(square), height+imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
lefthighH = line(mf_param(2)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'lefthigh');
righthighH = line(mf_param(4)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'righthigh');
elseif strcmp(mf_type, 'sigmf'),
a = mf_param(1);
c = mf_param(2);
height = 0.1;
leftlowH = line(c-log(1/height-1)/a + real(square), ...
height + imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
righthighH = line(c-log(1/(1-height)-1)/a + real(square), ...
1-height + imag(square), ...
'color', controlcolor, 'tag', 'righthigh');
elseif strcmp(mf_type, 'gbellmf'),
a = mf_param(1); b = mf_param(2); c = mf_param(3);
height = 0.9;
leftlowH = line(c-a+real(square), 0.5+imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
rightlowH = line(c+a+real(square), 0.5+imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
lefthighH = line(c-a*(1/height-1)^(1/(2*b))+real(square), ...
height+imag(square), 'color', controlcolor, 'tag', 'lefthigh');
righthighH = line(c+a*(1/height-1)^(1/(2*b))+real(square), ...
height+imag(square), 'color', controlcolor, 'tag', 'righthigh');
elseif strcmp(mf_type, 'smf'),
leftlowH = line(mf_param(1)+real(square), imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
righthighH = line(mf_param(2)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'righthigh');
elseif strcmp(mf_type, 'zmf'),
lefthighH = line(mf_param(1)+real(square), 1+imag(square), ...
'color', controlcolor, 'tag', 'lefthigh');
rightlowH = line(mf_param(2)+real(square), imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
elseif strcmp(mf_type, 'psigmf'),
a1=mf_param(1); c1=mf_param(2); a2=mf_param(3); c2=mf_param(4);
height = 0.9;
leftlowH = line(c1+real(square), 0.5+imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
rightlowH = line(c2+real(square), 0.5+imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
lefthighH = line(c1-log(1/height-1)/a1+real(square), ...
height+imag(square), ...
'color', controlcolor, 'tag', 'lefthigh');
righthighH = line(c2-log(1/height-1)/a2+real(square), ...
height+imag(square), ...
'color', controlcolor, 'tag', 'righthigh');
elseif strcmp(mf_type, 'dsigmf'),
a1=mf_param(1); c1=mf_param(2); a2=mf_param(3); c2=mf_param(4);
height = 0.9;
leftlowH = line(c1+real(square), 0.5+imag(square), ...
'color', controlcolor, 'tag', 'leftlow');
rightlowH = line(c2+real(square), 0.5+imag(square), ...
'color', controlcolor, 'tag', 'rightlow');
lefthighH = line(c1-log(1/height-1)/a1+real(square), ...
height+imag(square), ...
'color', controlcolor, 'tag', 'lefthigh');
righthighH = line(c2+log(1/height-1)/a2+real(square), ...
height+imag(square), ...
'color', controlcolor, 'tag', 'righthigh');
else
msgStr='not a default mf type';
statHndl=findobj(f, 'Tag', 'status');
set(statHndl, 'String', msgStr);
return
% fprintf('mf_type = %s\n', mf_type);
% error('Unknown MF type!');
end
% set mouse button-down function
set(f,'WindowButtonDownFcn',@localButtonDownFcn);
case 'info',
helpwin(mfilename);
end
%--------------------------------------------------------------------------
function localButtonDownFcn(eventSrc,eventData)
% local function for mouse button down action
%f = findobj(allchild(0),'type','figure','tag','mfedit');
f = eventSrc;
userparam=get(gca, 'Userdata');
if ~isstruct(userparam)
return
end
curr_info = get(gca, 'CurrentPoint');
leftlowH = findobj(f, 'tag', 'leftlow');
lefthighH = findobj(f, 'tag', 'lefthigh');
centerH = findobj(f, 'tag', 'center');
righthighH = findobj(f, 'tag', 'righthigh');
rightlowH = findobj(f, 'tag', 'rightlow');
lineH = findobj(f, 'tag', 'mfline', 'Userdata', userparam.CurrMF);
allH = [leftlowH lefthighH centerH righthighH rightlowH lineH];
set(allH, 'erasemode', 'xor');
% test if inside control squares
for i = 1:length(allH)-1,
set(allH(i), 'userdata', ...
find(inpolygon(curr_info(1,1),curr_info(1,2), ...
get(allH(i),'xdata')',get(allH(i),'ydata')')));
end
% test if clicking on the line
if isequal(gco,lineH),
param = eval(get(findobj(f, 'tag', 'mfparams'), 'string'));
set(findobj(f, 'tag', 'mfparams'), 'userdata', [curr_info(1,1) param]);
end
% store the current state and set the button motion function
fishist = get(f, 'Userdata');
fis = fishist{1}; % current fis
set(f,'WindowButtonUpFcn',{@localButtonUpFcn,fis},'WindowButtonMotionFcn',@localButtonMotionFcn);
%--------------------------------------------------------------------------
function localButtonMotionFcn(eventSrc,eventData)
% local function for mouse button motion action
selectColor = [1 0 0];
curr_info = get(gca, 'CurrentPoint');
%f = findobj(allchild(0),'type','figure','tag','mfedit');
f = eventSrc;
leftlowH = findobj(f, 'tag', 'leftlow');
rightlowH = findobj(f, 'tag', 'rightlow');
lefthighH = findobj(f, 'tag', 'lefthigh');
righthighH = findobj(f, 'tag', 'righthigh');
centerH = findobj(f, 'tag', 'center');
mainAxes = findobj(f, 'Tag','mainaxes');
paramLine = get(mainAxes, 'UserData');
lineH = findobj(f, 'tag', 'mfline', 'UserData', paramLine.CurrMF);
if ~isempty(lineH)
mf_type = deblank(feval(mfilename, 'get_current_mf'));
square = local_get_control_square;
paramH = findobj(f, 'tag', 'mfparams');
x = get(lineH, 'xdata');
mf_type = deblank(feval(mfilename, 'get_current_mf'));
paramstr=get(paramH, 'string');
if ~isempty(deblank(paramstr))
param = eval(paramstr);
else
param=[];
end
% Is the current variable input or output?
currVarAxes=findobj(f,'Type','axes','XColor',selectColor);
varIndex=get(currVarAxes,'UserData');
varType=get(currVarAxes,'Tag');
oldfis=get(f, 'Userdata');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -