⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfdrag.m

📁 交流 模糊控制 交流 模糊控制
💻 M
📖 第 1 页 / 共 3 页
字号:
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-2002 The MathWorks, Inc. 
% $Revision: 1.19 $ $Date: 2002/05/07 17:47:26 $
selectColor = [1 0 0];
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(gcf, 'tag', 'mftype'), 'value');
    out1 = mf_type(which_mf, :);
    out2=[];
    
case 'set_control_point',
    % delete all possible previous control points
    delete(findobj(gcf, 'tag', 'leftlow'));
    delete(findobj(gcf, 'tag', 'lefthigh'));
    delete(findobj(gcf, 'tag', 'center'));
    delete(findobj(gcf, 'tag', 'righthigh'));
    delete(findobj(gcf, '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(gcf, '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(gcf,'WindowButtonDownFcn',@localButtonDownFcn);
    
case 'info',
    helpwin(mfilename);
end

%--------------------------------------------------------------------------
function localButtonDownFcn(eventSrc,eventData)
% local function for mouse button down action

userparam=get(gca, 'Userdata');
if ~isstruct(userparam)
    return
end
curr_info = get(gca, 'CurrentPoint');
leftlowH = findobj(gcf, 'tag', 'leftlow');
lefthighH = findobj(gcf, 'tag', 'lefthigh');
centerH = findobj(gcf, 'tag', 'center');
righthighH = findobj(gcf, 'tag', 'righthigh');
rightlowH = findobj(gcf, 'tag', 'rightlow');
lineH = findobj(gcf, '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', ...
        inside(curr_info(1,1)+j*curr_info(1,2), ...
        get(allH(i),'xdata')'+j*get(allH(i),'ydata')'));
end
% test if clicking on the line
if gco == lineH,
    param = eval(get(findobj(gcf, 'tag', 'mfparams'), 'string'));
    set(findobj(gcf, 'tag', 'mfparams'), 'userdata', [curr_info(1,1) param]);
end

% store the current state and set the button motion function
fishist = get(gcf, 'Userdata');
fis = fishist{1}; % current fis
set(gcf,'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');

leftlowH = findobj(gcf, 'tag', 'leftlow');
rightlowH = findobj(gcf, 'tag', 'rightlow');
lefthighH = findobj(gcf, 'tag', 'lefthigh');
righthighH = findobj(gcf, 'tag', 'righthigh');
centerH = findobj(gcf, 'tag', 'center');
mainAxes = findobj(gcf, 'Tag','mainaxes');

paramLine = get(mainAxes, 'UserData');
lineH = findobj(gcf, 'tag', 'mfline', 'UserData', paramLine.CurrMF);
if ~isempty(lineH)
    
    mf_type = deblank(feval(mfilename, 'get_current_mf'));
    square = local_get_control_square;
    
    paramH = findobj(gcf, '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(gcf,'Type','axes','XColor',selectColor);
    varIndex=get(currVarAxes,'UserData');
    varType=get(currVarAxes,'Tag');
    oldfis=get(gcf, 'Userdata');
    fis=oldfis{1};
    if strcmp(mf_type, 'trimf'),
        if  get(leftlowH, 'userdata') & curr_info(1,1) <= param(2),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -