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

📄 wsdlg.m

📁 最新模糊逻辑工具箱
💻 M
字号:
function wsdlg(action,varName,dlgOption)
%WSDLG Create dialog for loading/saving FIS in workspace.
%   WSDLG(action,varName,dlgOption) creates a dialog box for either
%   saving to or reading from the workspace.
%
%   The FIS matrix is given the default workspace variable name varName.
%   The last input argument dlgOption defines whether or not you're passing
%   data into the workspace or out of it.

%   Ned Gulley, 9-15-94
%   Copyright (c) 1994-98 by The MathWorks, Inc.
%   $Revision: 1.14 $  $Date: 1997/12/01 21:46:02 $

if ~isstr(action),
    % For initialization, the fis matrix is passed in as the parameter
    fis=action;
    action='#initialize';
end;

if strcmp(action,'#initialize'),
    if strcmp(dlgOption,'gui2ws'), 
        labelStr='Save current FIS to workspace';
    else
        labelStr='Load FIS from workspace';
    end
    editLabel='Workspace variable';

    %===================================
    % Information for all objects
    frmColor=192/255*[1 1 1];
    btnColor=192/255*[1 1 1];
    popupColor=192/255*[1 1 1];
    editColor=255/255*[1 1 1];
    border=6;
    spacing=6;
    figPos=get(0,'DefaultFigurePosition');
    figPos(3:4)=[360 130];
    maxRight=figPos(3);
    maxTop=figPos(4);
    btnWid=160;
    btnHt=23;
 
    %====================================
    % The FIGURE
    figNumber=figure( ...
        'NumberTitle','off', ...
        'Color',[0.9 0.9 0.9], ...
        'Visible','off', ...
        'MenuBar','none', ...
        'UserData',fis, ...
        'Units','pixels', ...
        'Position',figPos, ...
        'Tag','gui2ws', ...
        'BackingStore','off');
    figPos=get(figNumber,'position');

    %====================================
    % The MAIN frame 
    top=maxTop-border;
    bottom=border; 
    right=maxRight-border;
    left=border;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
    right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 1 1 1];
    mainFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %====================================
    % The UPPER frame 
    top=maxTop-spacing-border;
    bottom=border+7*spacing+2*btnHt;
    right=maxRight-border-spacing;
    left=border+spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
    right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    varFrmHndl=uicontrol( ...
        'Units','pixel', ...
        'Style','frame', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    varSpacing=(top-bottom-2*btnHt);
    %------------------------------------
    % The STRING text field
    n=1;
    labelStr=labelStr;
    pos=[left top-btnHt*n-varSpacing*(n-1) right-left btnHt];
    uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'String',labelStr);



    %====================================
    % The EDIT FIELD frame 
    bottom=border+4*spacing+btnHt;
    top=bottom+btnHt;
    right=maxRight-border-spacing;
    left=border+spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    topFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %------------------------------------
    % The EDIT text field
    labelStr=editLabel;
    pos=[left top-btnHt btnWid btnHt];
    uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String',labelStr);

    %------------------------------------
    % The EDIT field
    varName=deblank(varName);
    varName=fliplr(deblank(fliplr(varName)));
    varName(find(varName==32))=95*ones(size(find(varName==32)));
    varName=[' ' varName];
    callbackStr='wsdlg #varname';
    pos=[right-btnWid top-btnHt btnWid btnHt];
    inputVarNameHndl=uicontrol( ...
        'Units','pixel', ...
        'Style','edit', ...
        'String',varName, ...
        'Callback',callbackStr, ...
        'Tag','edit', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',editColor);

    %====================================
    % The CLOSE frame 
    bottom=border+spacing;
    top=bottom+btnHt;
    right=maxRight-border-spacing;
    left=border+spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
    right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    clsFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %------------------------------------
    % The CANCEL button
    labelStr='Cancel';
    callbackStr='close(gcf)';
    infoHndl=uicontrol( ...
        'Style','push', ...
        'Position',[left bottom btnWid btnHt], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);

    %------------------------------------
    % The OKAY button
    labelStr='OK';
    if strcmp(dlgOption,'gui2ws'), 
        % This convoluted little callback builds the string that assigns
        % the current FIS matrix to the variable currently displayed in the
        % Edit field.
        callbackStr=[ ...
            ' newName=get(findobj(gcf,''Tag'',''edit''),''String''); ', ...
            ' fis=get(gcf,''UserData''); ', ...
            ' oldName=fis.name; ', ...
            ' fis.name = newName; ', ...
            ' s=[newName ''=fis;'']; ', ...
            ' eval(s); ', ...
            ' fisgui(''#fisname'',oldName,newName); ', ...
            ' close(gcf);' ];
    else
        % This callback builds the string that
        % opens the FIS Editor for the FIS matrix associated with 
        % the variable currently displayed in the Edit field.
        callbackStr=[ ...
            ' s=[get(findobj(gcf,''Tag'',''edit''),''String'')];', ...
            ' s=[''fuzzy('' s '');''];', ...
            ' f=gcf; ', ...
            ' eval(s); ', ...
            ' close(f);' ];
    end

    closeHndl=uicontrol( ...
        'Style','push', ...
        'Position',[right-btnWid bottom btnWid btnHt], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);

    % Normalize all coordinates
    hndlList=findobj(figNumber,'Units','pixels');
    set(hndlList,'Units','normalized');

    % Uncover the figure
    set(figNumber, ...
        'Visible','on');

elseif strcmp(action,'#varname'),
    % Every time the edit field is changed,
    % the new string is automatically deblanked front and back, replaced with 'null'
    % if it's empty, and reinserted.
    s=get(gco,'String');
    s=deblank(s);
    s=fliplr(deblank(fliplr(s)));
    if isempty(s), 
        s='null'; 
    end;
    s(find(s==32))=95*ones(size(find(s==32)));
    set(gco,'String',[' ' s]);

end

⌨️ 快捷键说明

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