image thumbnail

A toolbox for finding horseshoes in 2D maps

by

 

24 Feb 2007 (Updated )

This GUI programe presents an efficient method for finding topological horseshoes in chaotic systems

hsfind(varargin)
function varargout = hsfind(varargin)
% HSFIND M-file for hsfind.fig
%      HSFIND is a GUI programe for finding a topological horseshoe.
%
%      H = HSFIND returns the handle to a new HSFIND or the handle to
%      the existing singleton*.
%
%      HSFIND('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in HSFIND.M with the given input arguments.
%
%      HSFIND('Property','Value',...) creates a new HSFIND or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before hsfind_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to hsfind_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%      See also: GUIDE, GUIDATA, GUIHANDLES
%
% If you have any advice, please contact me.
% Author:  Dr. Qingdu Li
% Address: Institute for Nonlinear Systems, 
%     Chongqing University of Posts and Telecomm., Chongqing, 400065,China
% Email:   liqd@cqupt.edu.cn
% Reference: Qingdu Li and Xiao-Song Yang:A simple method for finding 
%            horseshoes

% Edit the above text to modify the response to help hsfind

% Last Modified by Qingdu Li v2.5 21-DEC-2008 18:08:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @hsfind_OpeningFcn, ...
                   'gui_OutputFcn',  @hsfind_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before hsfind is made visible.
function hsfind_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to hsfind (see VARARGIN)
% Choose default command line output for hsfind
clc;
handles.output = hObject;
% Update handles structure
Di.x=[];Di.xr=[];Di.rt=1;Di.rrt=1;Di.s=[1,3];
Di.h=[];Di.hr=[];
Di.hr1=[];Di.hr2=[];Di.h1=[];Di.h2=[];Di.hp=[];
Di.c='b';handles.Ds=Di;
Di.c='r';handles.Ds(2)=Di;
Di.c='g';handles.Ds(3)=Di;
Di.c='k';handles.Ds(4)=Di;
handles.id=1;
handles.npp=1;
handles.hnpp=[];
handles.rtfun='rtmapHenon';
handles.ni=50;
op.x='x';
op.y='y';
op.cdi1=[0,0.9,0];
op.cdi2=[0.9,0,0.9];
handles.op=op;

guidata(hObject, handles);

% --- Outputs from this function are returned to the command line.
function varargout = hsfind_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

function delfigh(h)
if ishandle(h)
    delete(h);
end

% --- Executes on button press in pb_Start.
function pb_Start_Callback(hObject, eventdata, handles)
% answer = inputdlg({'M-function of the return map:','Discard iterate times N:','Iterate Times k_max:'},'Get the numerical information',1,{handles.rtfun,'20','3000'});
% if isempty(answer),return;end
% handles.rtfun=answer{1};N1=eval(answer{2});N2=eval(answer{3});
handles.rtfun=get(handles.ed_mfun,'string');
N1=20;kmax=eval(get(handles.ed_kmax,'string'));

hw=waitbar(0,['Iterating the return map:' handles.rtfun]);
Xr=feval(handles.rtfun);
for i=1:kmax
    Xr=[Xr feval(handles.rtfun,Xr(:,end))];
    waitbar(i/kmax,hw);
end
close(hw);handles.Xr=Xr(:,N1+1:kmax);
hold(handles.axes1,'off');
handles.hfxe=plot(handles.Xr(1,:),handles.Xr(2,:),'b.','MarkerSize',1.5);
set(handles.hfxe,'Color',[0,0.4,0])
hold(handles.axes1,'on');
% handles.hfxr=plot(Xr(1,1:N1),Xr(2,1:N1),'b.','MarkerSize',4);
xlabel(['$' handles.op.x '$'],'Fontsize',15,'Interpreter','Latex');
ylabel(['$' handles.op.y '$'],'Fontsize',15,'Interpreter','Latex');
guidata(hObject, handles);

% --- Executes on button press in pb_ShowUPOs.
function pb_ShowUPOs_Callback(hObject, eventdata, handles)
% answer = inputdlg({'Enter the number of period:','Enter delta:'},'Input for UPOs',1,{'2','0.05'});
% if isempty(answer),return;end
% nP=eval(answer{1});
% delta=eval(answer{2});
nP=eval(get(handles.ed_l,'string'));
delta=eval(get(handles.ed_delta,'string'));
Xr=handles.Xr;
dr=Xr(:,nP+1:end)-Xr(:,1:end-nP);
dr=sum(dr.^2).^0.5;
k=find(dr<delta);
hUPOs=plot(Xr(1,k), Xr(2,k),'ko','MarkerSize',5);
if isfield(handles,'hUPOs')
        delfigh(handles.hUPOs);
end
handles.hUPOs=hUPOs;
guidata(hObject, handles);

% --- Executes on button press in pb_TakeDi.
function pb_TakeDi_Callback(hObject, eventdata, handles)
Dc=handles.Ds(handles.id);
[ph,Dc.x]=takeregion;
Dc.xr=Dc.x; D1=Dc.s(1)+[0,1];D2=Dc.s(2)+[0,1];
Dp=[D1,D2,D1,D2];
% Dc.s=['[1:' num2str(size(Dc.x,2)) ']'];
if ishandle(Dc.h)
    set(Dc.h,'XData',Dc.x(1,:),'YData',Dc.x(2,:));
    set(Dc.hr,'XData',Dc.x(1,:),'YData',Dc.x(2,:));
    set(Dc.hp,'XData',Dc.x(1,Dp),'YData',Dc.x(2,Dp));
    set(Dc.h1,'XData',Dc.x(1,D1),'YData',Dc.x(2,D1));
    set(Dc.h2,'XData',Dc.x(1,D2),'YData',Dc.x(2,D2));
    set(Dc.hr1,'XData',Dc.x(1,D1),'YData',Dc.x(2,D1));
    set(Dc.hr2,'XData',Dc.x(1,D2),'YData',Dc.x(2,D2));
    delfigh(ph);
else
    Dc.h=ph;
    Dc.hr=plot(Dc.x(1,:),Dc.x(2,:),'r-','LineWidth',0.5);
    Dc.hp=plot(Dc.x(1,Dp),Dc.x(2,Dp),'k.','Markersize',10);
    Dc.h1=plot(Dc.x(1,D1),Dc.x(2,D1),'r-','LineWidth',2);
    Dc.h2=plot(Dc.x(1,D2),Dc.x(2,D2),'r-','LineWidth',2);
    Dc.hr1=plot(Dc.x(1,D1),Dc.x(2,D1),'r-','LineWidth',2);
    Dc.hr2=plot(Dc.x(1,D2),Dc.x(2,D2),'r-','LineWidth',2);
    set(Dc.hr,'Color',Dc.c);c=get(Dc.hr,'Color');set(Dc.h,'Color',c*0.5);
    set(Dc.h1,'Color',handles.op.cdi1);set(Dc.h2,'Color',handles.op.cdi2);
    set(Dc.hr1,'Color',handles.op.cdi1);set(Dc.hr2,'Color',handles.op.cdi2);
end
handles.Ds(handles.id)=Dc;
guidata(hObject, handles);

% Take a region from a 2d plot.
function [hregion,x]=takeregion
x=ginput(1)';
hregion=plot(x(1),x(2),'m.-','Markersize',5);
while 1
    [tx,ty,bt]=ginput(1);
    if bt==1
        x=[x [tx; ty]];set(hregion,'XData',x(1,:),'YData',x(2,:));
    else
        if size(x,2)>3
        x=[x x(:,1)];set(hregion,'XData',x(1,:),'YData',x(2,:));
        end
        break;
    end
end

% --- Executes on button press in pb_Calculate.
function pb_Calculate_Callback(hObject, eventdata, handles)
% hObject    handle to pb_Calculate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Dc=handles.Ds(handles.id);
% answer = inputdlg({'Return time:m=i * l or n','Insert points:','Side line'},...
%     'Input for calculate poincare maps',1,...
%     {num2str(Dc.rt),'50',mat2str(Dc.s)});
% if isempty(answer),return;end
% Dc.rt=eval(answer{1});ni=eval(answer{2});s=eval(answer{3});
ni=handles.ni;
hw=waitbar(0,'Calculating the return map');
Dc.xr=[];N=(size(Dc.x,2)-1)*ni;
for i=1:size(Dc.x,2)-1
    dx=(Dc.x(:,i+1)-Dc.x(:,i))/ni;
    for j=0:ni-1
        x0=Dc.x(:,i)+j*dx;for ir=1:Dc.rt,x0=feval(handles.rtfun,x0);end
        Dc.xr=[Dc.xr x0];
        waitbar(((i-1)*ni+j)/N,hw);
    end
end
Dc.xr=[Dc.xr Dc.xr(:,1)];
close(hw);

set(Dc.hr,'Xdata',Dc.xr(1,:),'Ydata',Dc.xr(2,:));
D1=(Dc.s(1)-1)*ni+[1:ni+1];D2=(Dc.s(2)-1)*ni+[1:ni+1];
set(Dc.hr1,'Xdata',Dc.xr(1,D1),'Ydata',Dc.xr(2,D1));
set(Dc.hr2,'Xdata',Dc.xr(1,D2),'Ydata',Dc.xr(2,D2));

Dp=[Dc.s(1)+[0,1] Dc.s(2)+[0,1]];
Dpr=[(Dc.s(1)-1)*ni+[1,ni+1] (Dc.s(2)-1)*ni+[1,ni+1]];
x=[Dc.x(:,Dp) Dc.xr(1:2,Dpr)];
set(Dc.hp,'Xdata',x(1,:),'Ydata',x(2,:));
handles.Ds(handles.id)=Dc;
guidata(hObject, handles);



% --- Executes on button press in pb_ShowD1Prepoint.
function pb_ShowD1Prepoint_Callback(hObject, eventdata, handles)
% hObject    handle to pb_ShowD1Prepoint (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Dc=handles.Ds(handles.id);
% if ~isfield(handles,'npp'),handles.npp=1;end;
% answer = inputdlg({'The nth point before the point in D1'},...
%     'Input for locate D2',1,...
%     {num2str(handles.npp)});
% if isempty(answer),return;end
% handles.npp=eval(answer{1});

IN = find(inpolygon(handles.Xr(1,:),handles.Xr(2,:),Dc.x(1,:),Dc.x(2,:)))-handles.npp;
IN=IN(IN>1);
delfigh(handles.hnpp);
handles.hnpp=plot(handles.Xr(1,IN),handles.Xr(2,IN),'r.','MarkerSize',6);
guidata(hObject, handles);

function ed_mfun_Callback(hObject, eventdata, handles)
% hObject    handle to ed_mfun (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_mfun as text
%        str2double(get(hObject,'String')) returns contents of ed_mfun as a double
handles.rtfun=get(handles.ed_mfun,'string');
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function ed_mfun_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_mfun (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function ed_kmax_Callback(hObject, eventdata, handles)
% hObject    handle to ed_kmax (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_kmax as text
%        str2double(get(hObject,'String')) returns contents of ed_kmax as a double


% --- Executes during object creation, after setting all properties.
function ed_kmax_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_kmax (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function ed_l_Callback(hObject, eventdata, handles)
% hObject    handle to ed_l (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_l as text
%        str2double(get(hObject,'String')) returns contents of ed_l as a double


% --- Executes during object creation, after setting all properties.
function ed_l_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_l (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function ed_delta_Callback(hObject, eventdata, handles)
% hObject    handle to ed_delta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_delta as text
%        str2double(get(hObject,'String')) returns contents of ed_delta as a double


% --- Executes during object creation, after setting all properties.
function ed_delta_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_delta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in lb_selectDi.
function lb_selectDi_Callback(hObject, eventdata, handles)
% hObject    handle to lb_selectDi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns lb_selectDi contents as cell array
%        contents{get(hObject,'Value')} returns selected item from lb_selectDi
handles.id=get(handles.lb_selectDi,'value');
s=get(handles.txt_ppd,'string');
s(2)={sprintf('D_%d^1     D_%d^2', handles.id,handles.id)};
set(handles.txt_ppd,'string',s);
set(handles.pb_TakeDi,'string',sprintf('Take D_%d', handles.id));

Dc=handles.Ds(handles.id);
set(handles.ed_m,'string',num2str(Dc.rt));
set(handles.ed_pp,'string',mat2str(Dc.s));

st=sprintf('H^%d(D_%d)',Dc.rt,handles.id);
set(handles.pb_Calculate,'string',st);
st=sprintf('H^{-%d}(S_D_%d)',Dc.rrt,handles.id);
set(handles.pb_ShowDiPrepoint,'string',st);
handles.npp=Dc.rrt;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function lb_selectDi_CreateFcn(hObject, eventdata, handles)
% hObject    handle to lb_selectDi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function ed_pp_Callback(hObject, eventdata, handles)
% hObject    handle to ed_pp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_pp as text
%        str2double(get(hObject,'String')) returns contents of ed_pp as a double
s=eval(get(handles.ed_pp,'string'));
handles.Ds(handles.id).s=s;
guidata(hObject, handles);

Dc=handles.Ds(handles.id);
if isempty(Dc.x), return;end;
ni=handles.ni;
D1=Dc.s(1)+[0,1];D2=Dc.s(2)+[0,1];
set(Dc.h1,'Xdata',Dc.x(1,D1),'Ydata',Dc.x(2,D1));
set(Dc.h2,'Xdata',Dc.x(1,D2),'Ydata',Dc.x(2,D2));

Dp=[D1 D2];
Dpr=Dp;
if length(Dc.xr)>length(Dc.x)
    D1=(Dc.s(1)-1)*ni+[1:ni+1];D2=(Dc.s(2)-1)*ni+[1:ni+1];
    Dpr=[(Dc.s(1)-1)*ni+[1,ni+1] (Dc.s(2)-1)*ni+[1,ni+1]];
end
set(Dc.hr1,'Xdata',Dc.xr(1,D1),'Ydata',Dc.xr(2,D1));
set(Dc.hr2,'Xdata',Dc.xr(1,D2),'Ydata',Dc.xr(2,D2));
x=[Dc.x(:,Dp) Dc.xr(:,Dpr)];
set(Dc.hp,'Xdata',x(1,:),'Ydata',x(2,:));

% --- Executes during object creation, after setting all properties.
function ed_pp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_pp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function ed_m_Callback(hObject, eventdata, handles)
% hObject    handle to ed_m (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_m as text
%        str2double(get(hObject,'String')) returns contents of ed_m as a double

nrt=eval(get(handles.ed_m,'string'));
handles.Ds(handles.id).rt=nrt;

st=sprintf('H^%d(D_%d)',nrt,handles.id);
set(handles.pb_Calculate,'string',st);
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function ed_m_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_m (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function ed_n_Callback(hObject, eventdata, handles)
% hObject    handle to ed_n (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ed_n as text
%        str2double(get(hObject,'String')) returns contents of ed_n as a double
rrt=eval(get(handles.ed_n,'string'));
handles.Ds(handles.id).rrt=rrt;
handles.npp=rrt;
st=sprintf('H^{-%d}(S_D_%d)',rrt,handles.id);
set(handles.pb_ShowDiPrepoint,'string',st);
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function ed_n_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ed_n (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pb_Load.
function pb_Load_Callback(hObject, eventdata, handles)
% hObject    handle to pb_Load (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
hd=handles;
fn=['hsmap_' handles.rtfun '.mat'];
load(fn);
hd.Ds=handles.Ds;
hd.id=handles.id;
hd.rtfun=handles.rtfun;
hd.ni=handles.ni;
hd.op=handles.op;
hd.npp=handles.npp;
hd.hnpp=[];
hd.Xr=handles.Xr;
hd.hfxe=[];
hd.hUPOs=[];
handles=hd;
cla;
handles.hfxe=plot(handles.Xr(1,:),handles.Xr(2,:),'b.','MarkerSize',2);
set(handles.hfxe,'Color',[0,0.4,0])
hold on;
for i=1:length(handles.Ds)
    Dc=handles.Ds(i);
    if isempty(Dc.x),continue;end
    Dc.h=plot(Dc.x(1,:),Dc.x(2,:),'r-','LineWidth',0.5);
    Dc.hr=plot(Dc.xr(1,:),Dc.xr(2,:),'r-','LineWidth',0.5);
    D1=Dc.s(1)+[0,1];D2=Dc.s(2)+[0,1];
    Dc.h1=plot(Dc.x(1,D1),Dc.x(2,D1),'r-','LineWidth',2);
    Dc.h2=plot(Dc.x(1,D2),Dc.x(2,D2),'r-','LineWidth',2);
    
    Dp=[D1 D2];Dpr=Dp;
    if length(Dc.xr)>length(Dc.x)
        ni=handles.ni;D1=(Dc.s(1)-1)*ni+[1:ni+1];D2=(Dc.s(2)-1)*ni+[1:ni+1];
        Dpr=[(Dc.s(1)-1)*ni+[1,ni+1] (Dc.s(2)-1)*ni+[1,ni+1]];
    end
    x=[Dc.x(:,Dp) Dc.xr(:,Dpr)];
    Dc.hp=plot(x(1,:),x(2,:),'k.','Markersize',10);
    Dc.hr1=plot(Dc.xr(1,D1),Dc.xr(2,D1),'r-','LineWidth',2);
    Dc.hr2=plot(Dc.xr(1,D2),Dc.xr(2,D2),'r-','LineWidth',2);
    set(Dc.hr,'Color',Dc.c);c=get(Dc.hr,'Color');set(Dc.h,'Color',c*0.5);
    set(Dc.h1,'Color',handles.op.cdi1);set(Dc.h2,'Color',handles.op.cdi2);
    set(Dc.hr1,'Color',handles.op.cdi1);set(Dc.hr2,'Color',handles.op.cdi2);
    handles.Ds(i)=Dc;
end
set(handles.lb_selectDi,'value',handles.id);
lb_selectDi_Callback(hObject, eventdata, handles);
guidata(hObject, handles);




% --- Executes on button press in pb_Save.
function pb_Save_Callback(hObject, eventdata, handles)
% hObject    handle to pb_Save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fn=['hsmap_' handles.rtfun '.mat'];
save(fn,'handles');

% --- Executes on button press in pb_setting.
function pb_setting_Callback(hObject, eventdata, handles)
op=handles.op;
answer = inputdlg({'Insert ? points for each border','xlabel','ylabel',...
    'Color of D_i^1','Color of D_i^2'},...
     'Setting options',1,...
     {num2str(handles.ni),op.x,op.y,mat2str(op.cdi1),mat2str(op.cdi2)});
if isempty(answer),return;end
handles.ni=eval(answer{1});
op.x=answer{2};
op.y=answer{3};
op.cdi1=eval(answer{4});
op.cdi2=eval(answer{5});
handles.op=op;
xlabel(['$' handles.op.x '$'],'Fontsize',15,'Interpreter','Latex');
ylabel(['$' handles.op.y '$'],'Fontsize',15,'Interpreter','Latex');
for i=1:length(handles.Ds)
    Dc=handles.Ds(i);
    set(Dc.h1,'Color',handles.op.cdi1);set(Dc.h2,'Color',handles.op.cdi2);
    set(Dc.hr1,'Color',handles.op.cdi1);set(Dc.hr2,'Color',handles.op.cdi2);
end
guidata(hObject, handles);

% --- Executes on button press in pb_plotmap.
function pb_plotmap_Callback(hObject, eventdata, handles)
h=figure;hold on;
xlabel(['$' handles.op.x '$'],'Fontsize',15,'Interpreter','Latex');
ylabel(['$' handles.op.y '$'],'Fontsize',15,'Interpreter','Latex');
clc;
for i=1:length(handles.Ds)
    Dc=handles.Ds(i);
    if isempty(Dc.x),continue;end
    
    Dc.h=plot(Dc.x(1,:),Dc.x(2,:),'r-','LineWidth',0.5);
    D1=Dc.s(1)+[0,1];D2=Dc.s(2)+[0,1];
    Dc.h1=plot(Dc.x(1,D1),Dc.x(2,D1),'r-','LineWidth',2);
    Dc.h2=plot(Dc.x(1,D2),Dc.x(2,D2),'r-','LineWidth',2);
    set(Dc.h,'Color',Dc.c);c=get(Dc.h,'Color');set(Dc.h,'Color',c*0.5);
    set(Dc.h1,'Color',handles.op.cdi1);set(Dc.h2,'Color',handles.op.cdi2);
    txtsym(mean(Dc.x'),sprintf('D_%d',i));
    txtsym(mean(Dc.x(:,D1)'),sprintf('D_%d^1',i));
    txtsym(mean(Dc.x(:,D2)'),sprintf('D_%d^2',i));
    disp(sprintf('The %d vertices of D_%d are',size(Dc.x,2)-1,i));
    for iv=1:size(Dc.x,2)-1
    disp(sprintf('$[%.9f,%.9f]^T$',Dc.x(1,iv),Dc.x(2,iv)));
    end
    
    Dc.hr=plot(Dc.xr(1,:),Dc.xr(2,:),'r-','LineWidth',0.5);    
    Dp=[D1 D2];Dpr=Dp;
    if length(Dc.xr)>length(Dc.x)
        ni=handles.ni;D1=(Dc.s(1)-1)*ni+[1:ni+1];D2=(Dc.s(2)-1)*ni+[1:ni+1];
        Dpr=[(Dc.s(1)-1)*ni+[1,ni+1] (Dc.s(2)-1)*ni+[1,ni+1]];
    end
    x=[Dc.x(:,Dp) Dc.xr(:,Dpr)];
    Dc.hp=plot(x(1,:),x(2,:),'k.','Markersize',10);
    Dc.hr1=plot(Dc.xr(1,D1),Dc.xr(2,D1),'r-','LineWidth',2);
    Dc.hr2=plot(Dc.xr(1,D2),Dc.xr(2,D2),'r-','LineWidth',2);
    set(Dc.hr,'Color',Dc.c);
    set(Dc.hr1,'Color',handles.op.cdi1);set(Dc.hr2,'Color',handles.op.cdi2);
    if(Dc.rt==1)
        txtsym(mean(Dc.xr'),sprintf('H(D_%d)',i));
        txtsym(mean(Dc.xr(:,D1)'),sprintf('H(D_%d^1)',i));
        txtsym(mean(Dc.xr(:,D2)'),sprintf('H(D_%d^2)',i));  
    else
        txtsym(mean(Dc.xr'),sprintf('H^%d(D_%d)',Dc.rt,i));
        txtsym(mean(Dc.xr(:,D1)'),sprintf('H^%d(D_%d^1)',Dc.rt,i));
        txtsym(mean(Dc.xr(:,D2)'),sprintf('H^%d(D_%d^2)',Dc.rt,i));
    end
end

function txtsym(x,s)
text(x(1),x(2),['$' s '$'],'Fontsize',12,'Interpreter','Latex');


% --- Executes on button press in pb_labelDi.
function pb_labelDi_Callback(hObject, eventdata, handles)
% hObject    handle to pb_labelDi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Dc=handles.Ds(handles.id);
if isempty(Dc.x),return;end
i=handles.id;
D1=Dc.s(1)+[0,1];D2=Dc.s(2)+[0,1];
txtsym(mean(Dc.x'),sprintf('D_%d',i));
txtsym(mean(Dc.x(:,D1)'),sprintf('D_%d^1',i));
txtsym(mean(Dc.x(:,D2)'),sprintf('D_%d^2',i));
if length(Dc.xr)>length(Dc.x)
    ni=handles.ni;D1=(Dc.s(1)-1)*ni+[1:ni+1];D2=(Dc.s(2)-1)*ni+[1:ni+1];
end
if(Dc.rt==1)
    txtsym(mean(Dc.xr'),sprintf('H(D_%d)',i));
    txtsym(mean(Dc.xr(:,D1)'),sprintf('H(D_%d^1)',i));
    txtsym(mean(Dc.xr(:,D2)'),sprintf('H(D_%d^2)',i));
else
    txtsym(mean(Dc.xr'),sprintf('H^%d(D_%d)',Dc.rt,i));
    txtsym(mean(Dc.xr(:,D1)'),sprintf('H^%d(D_%d^1)',Dc.rt,i));
    txtsym(mean(Dc.xr(:,D2)'),sprintf('H^%d(D_%d^2)',Dc.rt,i));
end

% --- Executes on button press in pb_unlabel.
function pb_unlabel_Callback(hObject, eventdata, handles)
% hObject    handle to pb_unlabel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
hs= findobj(gca,'Type','Text');
for i=1:length(hs)
    delfigh(hs(i));
end

Contact us