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

📄 attractor.m

📁 一个混沌信号产生器MATLAB源代码。主要用于产生混沌信号序列。
💻 M
📖 第 1 页 / 共 2 页
字号:
%           where k arbitrary
%      - tentmap1: tent like map 1
%                  /
%                  | k*x[n-1]       , if (0<=x[n-1]) & (x[n-1]<1/3)
%           x[n] = | k*(2/3-x[n-1]) , if (1/3<=x[n-1]) & (x[n-1]<2/3)
%                  | k*(-2/3+x[n-1]), otherwise
%                  \
%           where k arbitrary
%      - tentmap2: tent like map 2
%                  /
%                  | k*x[n-1]             , if (0<=x[n-1]) & (x[n-1]<1/4)
%           x[n] = | sqrt(k)*(1-2*x[n-1]) , if (1/4<=x[n-1]) & (x[n-1]<1/2)
%                  | sqrt(k)*(2*x[n-1]-1) , if (1/2<=x[n-1]) & (x[n-1]<3/4)
%                  | k*(1-x[n-1])         , otherwise
%                  \
%           where k arbitrary
%      - tentmap: tent map
%           x[n] = k*(1-abs(1-2*x[n-1]))
%           where k arbitrary

if nargin==0
	
   %set paths 
   addpath([pwd '\Cont']);
   addpath([pwd '\Discr']);
   addpath([pwd '\Prvt']);
   %initialize GUI
   srtAttractorGUI;
   %set default generator (ChuaCirc)
%    d=dir('Cont');
%    str = {d.name};
%    s=cell2struct(str(3),{'str'},1);
%    fcname=s.str(1:end-2);
   hndf=gcf;
   set(findobj(hndf,'Tag','popupGT'), 'Value', 1);
   fcname = 'ChuaCirc';
   set(findobj(hndf,'Tag','edtTitle'),'FontSize',10,'String',fcname)
   %set default values
   structData=AttInit(fcname);
   vSelVar=structData.SelVar;
   y0=structData.InitCond;
   rParam=structData.ParamVal;
   vTimeRange=structData.TimeRange;
   if ~isempty(vSelVar) | ~isempty(y0) | ~isempty(rParam) | ~isempty(vTimeRange)
       %display default values
       cla
       set(findobj(hndf,'Tag','edtSelVar'),'String',num2str(vSelVar,2));
       set(findobj(hndf,'Tag','edtInitCond'),'String',num2str(y0,2));
       set(findobj(hndf,'Tag','edtParamVal'),'String',num2str(rParam));
       set(findobj(hndf,'Tag','edtTimeRange'),'String',num2str(vTimeRange,2));
       set(findobj(hndf,'Tag','txtVal'),'String',[])
   end
elseif strcmp(action,'Start')
   hndf=gcf;
   %set buttons
   set(findobj(hndf,'Tag','btnStop'), 'Enable', 'on');
   set(findobj(hndf,'Tag','btnNewPlot'), 'Enable', 'off');
   set(findobj(hndf,'Tag','btnExit'), 'Enable', 'off');
   set(findobj(hndf,'Tag','btnBrowse'), 'Enable', 'off');
   set(findobj(hndf,'Tag','popupGT'), 'Enable', 'off');
   %get current values
   fcname=get(findobj(hndf,'Tag','edtTitle'),'String');
   vSelVar=str2num(get(findobj(hndf,'Tag','edtSelVar'),'String'));
   y0=str2num(get(findobj(hndf,'Tag','edtInitCond'),'String'));
   rParam=str2num(get(findobj(hndf,'Tag','edtParamVal'),'String'));
   vTimeRange=str2num(get(findobj(hndf,'Tag','edtTimeRange'),'String'));
   nVal=get(findobj(hndf,'Tag','popupGT'),'Value');
   %select solver
   if nVal==1
   	   options=odeset('OutputFcn','m_odephas2','OutputSel',vSelVar);
       ode45(fcname,vTimeRange,y0,options,rParam);
   elseif nVal==2
	   m_dre(fcname,vTimeRange,y0,rParam)
   end
   %set buttons
   set(findobj(hndf,'Tag','btnStop'), 'Enable', 'off');
   set(findobj(hndf,'Tag','btnNewPlot'), 'Enable', 'on');
   set(findobj(hndf,'Tag','btnExit'), 'Enable', 'on');
   set(findobj(hndf,'Tag','btnBrowse'), 'Enable', 'on');
   set(findobj(hndf,'Tag','popupGT'), 'Enable', 'on');
elseif strcmp(action,'Stop')
   hndf=gcf;
   %set buttons
   set(findobj(hndf,'Tag','btnStart'), 'Enable', 'on');
   set(findobj(hndf,'Tag','btnStop'), 'Enable', 'off');
   set(findobj(hndf,'Tag','btnNewPlot'), 'Enable', 'on');
   set(findobj(hndf,'Tag','btnExit'), 'Enable', 'on');
   set(findobj(hndf,'Tag','btnBrowse'), 'Enable', 'on');
   set(findobj(hndf,'Tag','popupGT'), 'Enable', 'on');
   %set flag
   ud=get(hndf,'UserData');
   ud.stop=1;
   set(hndf,'UserData',ud);
elseif strcmp(action,'NewPlot')
   hndf=gcf;
   ud=get(hndf,'UserData');
   fcname=get(findobj(hndf,'Tag','edtTitle'),'String');
   h0 = figure('Units','normalized','Color',[1 1 1],'Name','2D Attractor - new plot', ...
   		'ToolBar','none','Numbertitle','off','Position',[0.15 0.15 0.65 0.7]);
   axes('Parent',h0,'Position',[0.07 0.07 0.87 0.85]);
   box
   if get(findobj(hndf,'Tag','popupGT'),'Value')==2 & ...
	  ~str2num(get(findobj(hndf,'Tag','edtSelVar'),'String'))
  		plot(ud.y(:,1),ud.y(:,2),'.')
   else
   		plot(ud.y(:,1),ud.y(:,2))
   end
   axis tight
   %Text : axes title
	uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 0],'Position',[0.255 0.925 0.5 0.05],'Style','text', ...
   'String',fcname,'FontSize',15);
elseif strcmp(action,'GT')
    nVal=get(findobj(gcf,'Tag','popupGT'),'Value');%get generator type {Cont, Discr}
   	hndf=gcf;
	%modify GUI
	cla
	set(findobj(hndf,'Tag','edtTitle'),'String',[])
	set(findobj(hndf,'Tag','edtSelVar'),'String',[])
	set(findobj(hndf,'Tag','edtInitCond'),'String',[])
	set(findobj(hndf,'Tag','edtParamVal'),'String',[])
	set(findobj(hndf,'Tag','edtTimeRange'),'String',[])
	set(findobj(hndf,'Tag','txtVal'),'String',[])
    set(findobj(hndf,'Tag','btnStart'),'Enable','off')
    set(findobj(hndf,'Tag','btnStop'),'Enable','off')
    set(findobj(hndf,'Tag','btnNewPlot'),'Enable','off')
    set(findobj(hndf,'Tag','btnBrowse'),'Enable','on')
    if nVal==1 %Cont
		set(findobj(hndf,'Tag','txtSelVar'),'String','Select variables');
		set(findobj(hndf,'Tag','txtTimeRange'),'String','Time range');
    elseif nVal==2 %Discr
		set(findobj(hndf,'Tag','txtSelVar'),'String','Plotting style');
		set(findobj(hndf,'Tag','txtTimeRange'),'String','Iterations');
    end	
elseif strcmp(action,'Browse')
    nVal=get(findobj(gcf,'Tag','popupGT'),'Value');%get generator type {Cont, Discr}
    if nVal==1
        d=dir('Cont');
    elseif nVal==2
        d=dir('Discr');
    end
    str = {d.name};
    [Selection,ok] = listdlg('PromptString','Select a file:',...
                'SelectionMode','single',...
                'ListString',str(3:end));
    if ok
        s=cell2struct(str(2+Selection),{'str'},1);
        fcname=s.str(1:end-2);
		hndf=gcf;
		set(findobj(hndf,'Tag','edtTitle'),'FontSize',10,'String',fcname)
		%set default values
	   	structData=AttInit(fcname);
		vSelVar=structData.SelVar;
	   	y0=structData.InitCond;
	   	rParam=structData.ParamVal;
	   	vTimeRange=structData.TimeRange;
   		if ~isempty(vSelVar) | ~isempty(y0) | ~isempty(rParam) | ~isempty(vTimeRange)
			%display default values 
			cla
   			set(findobj(hndf,'Tag','edtSelVar'),'String',num2str(vSelVar,2));
   			set(findobj(hndf,'Tag','edtInitCond'),'String',num2str(y0,2));
   			set(findobj(hndf,'Tag','edtParamVal'),'String',num2str(rParam));
   			set(findobj(hndf,'Tag','edtTimeRange'),'String',num2str(vTimeRange,2));
			set(findobj(hndf,'Tag','txtVal'),'String',[]);
        end
        %set buttons
        set(findobj(hndf,'Tag','btnStart'), 'Enable', 'on');
        set(findobj(hndf,'Tag','btnStop'), 'Enable', 'off');
        set(findobj(hndf,'Tag','btnNewPlot'), 'Enable', 'off');
    end
elseif strcmp(action,'Exit')
	%clear global variables
	clear global
   	%clear paths 
  	rmpath([pwd '\Cont']);
   	rmpath([pwd '\Discr']);
  	rmpath([pwd '\Prvt']);
	%close figure
	close(gcf)
	
end

%---------------- subroutine -----------------
function srtAttractorGUI
%creates a GUI for attractors drawing

%Callback strings
cbstrStart='attractor(''Start'')';
cbstrStop='attractor(''Stop'')';
cbstrNewPlot='attractor(''NewPlot'')';
cbstrHelp='helpwin(''attractor'','''',''2D Attractor Help Window'')';
cbstrGT='attractor(''GT'')';
cbstrBrowse='attractor(''Browse'')';
cbstrExit='attractor(''Exit'')';

WinWidth=0.8;		%Window width
WinHeight=0.78;   %Window height
BtnWidth=0.12;		%Button width
BtnHeight=0.05;   %Button height
xPos=0.865;       %X-position of buttons

h0 = figure('Units','normalized','Color',[1 1 1],'Name','2D Attractor','NumberTitle','off', ...
   'Position',[0.1 0.1 WinWidth WinHeight],'MenuBar','none','ToolBar','none', ...
   'Resize','off','Visible','off');

%Frame : left
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[0.513725 0.6 0.694118], ...
   'Position',[0.85 0 0.15 1],'Style','frame');
%Frame : bottom
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[0.513725 0.6 0.694118], ...
   'Position',[0 0 0.85 0.0676],'Style','frame');
%Button : start
uicontrol('Parent',h0,'Units','normalized','Position',[xPos 0.94 BtnWidth BtnHeight], ...
   'String','Start','Tag','btnStart','Callback',cbstrStart,'Enable','on');
%Button : stop
uicontrol('Parent',h0,'Units','normalized','Position',[xPos 0.88 BtnWidth BtnHeight], ...
   'String','Stop','Tag','btnStop','Callback',cbstrStop,'Enable','off');
%Button : new plot
uicontrol('Parent',h0,'Units','normalized','Position',[xPos 0.82 BtnWidth BtnHeight], ...
   'String','New plot','Tag','btnNewPlot','Callback',cbstrNewPlot,'Enable','off');
%Text : select variables
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[0.513725 0.6 0.694118], ...
   'Position',[xPos 0.68 BtnWidth BtnHeight],'String','Select variables','Style','text', ...
   'Tag','txtSelVar');
%Edit : select variables
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 1],'Position',[xPos 0.64 BtnWidth BtnHeight],'Style','edit', ...
   'Tag','edtSelVar');
%Text : initial conditions
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[0.513725 0.6 0.694118], ...
   'Position',[xPos 0.56 BtnWidth BtnHeight],'String','Initial cond.','Style','text');
%Edit : initial conditions
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 1],'Position',[xPos 0.52 BtnWidth BtnHeight],'Style','edit', ...
   'Tag','edtInitCond');
%Text : parameter value
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[0.513725 0.6 0.694118], ...
   'Position',[xPos 0.44 BtnWidth BtnHeight],'String','Parameter value','Style','text');
%Edit : parameter value
edtInitTime = uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 1],'Position',[xPos 0.4 BtnWidth BtnHeight],'Style','edit', ...
   'Tag','edtParamVal');
%Text : time range
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[0.513725 0.6 0.694118], ...
   'Position',[xPos 0.32 BtnWidth BtnHeight],'String','Time range','Style','text', ...
   'Tag','txtTimeRange');
%Edit : time range
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 1],'Position',[xPos 0.28 BtnWidth BtnHeight],'Style','edit', ...
   'Tag','edtTimeRange');
%Button : help
uicontrol('Parent',h0,'Units','normalized','Position',[xPos 0.12 BtnWidth BtnHeight], ...
   'String','Help','Tag','btnHelp','Callback',cbstrHelp,'Enable','on');
%Button : exit
uicontrol('Parent',h0,'Units','normalized','Position',[xPos 0.06 BtnWidth BtnHeight], ...
   'String','Exit','Tag','btnExit','Callback',cbstrExit,'Enable','on');
%Axes
axes('Parent',h0,'Position',[0.07 0.15 0.75 0.75]);
box
%Popup : generator type
uicontrol('Parent',h0,'Units','normalized','Position',[0.14 0.912 0.16 0.05], ...
    'BackgroundColor',[1 1 1],'ForegroundColor',[0 0 0],'Style','popup', ...
    'String','Time continuous|Time discrete','Value',1,'Tag','popupGT','Callback',cbstrGT,'Enable','on');
%Edit : axes title
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 0],'Position',[0.3 0.915 0.3 0.05],'Style','edit', ...
   'Tag','edtTitle');
%Button : browse
uicontrol('Parent',h0,'Units','normalized','Position',[0.603 0.92 0.03 0.04], ...
    'Style','pushbutton','String','...','Callback',cbstrBrowse, ...
    'Tag', 'btnBrowse','Enable','on');
%Text : current values and time
uicontrol('Parent',h0,'Units','normalized','BackgroundColor',[1 1 1], ...
   'ForegroundColor',[0 0 1],'Position',[0.0057 0.01 0.835 0.045],'Style','text', ...
   'Tag','txtVal');

set(h0,'Visible','on');

⌨️ 快捷键说明

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