clear;clc
cd '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+运行数据'
addpath('/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+程序代码')
addpath('/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件')
load('Data_use.mat');
%% 附录III  中国经济内循环贸易壁垒的空间特征
% 地区层面
figure(1)
clf
M_0 = 0.75:-0.02:0.2;
M_1 = [1 1 1];
map = M_0'*M_1;
subplot(2,3,1)
NA_DTB = [Reg_dtbp(:) Reg_dtbp_Adj(:)]; 
[~,density,X,Y]=kde2d(NA_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（a）核密度分布（全国）','FontSize',12,'FontName','Songti SC')
subplot(2,3,4); 
contour(X,Y,density,75)
axis([-1 8 -1 8])
hold on 
x=-1:1:8;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
title('（b）密度等高线（全国）','FontSize',12,'FontName','Songti SC')
subplot(2,3,2)
Coa_DTB = [Coa_dtb(:) Coa_dtb_adj(:)]; 
[~,density,X,Y]=kde2d(Coa_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（c）核密度分布（沿海）','FontSize',12,'FontName','Songti SC')
subplot(2,3,5); 
contour(X,Y,density,75)
axis([-1 8 -1 8])
hold on 
x=-1:1:8;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
title('（d）密度等高线（沿海）','FontSize',12,'FontName','Songti SC')
subplot(2,3,3)
IN_DTB = [In_dtb(:) In_dtb_adj(:)]; 
[~,density,X,Y]=kde2d(IN_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（e）核密度分布（内陆）','FontSize',12,'FontName','Songti SC')
subplot(2,3,6); 
contour(X,Y,density,75)
axis([-1 8 -1 8])
hold on 
x=-1:1:8;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
title('（f）密度等高线（内陆）','FontSize',12,'FontName','Songti SC')
colormap(map)
set(gcf,'position',[0,0,1200,550],'color','white'); 
fn_III_1 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/figure_III_1.tif';
saveas(gcf,fn_III_1,'tif');

% 部门层面 
figure(2)
clf
M_0 = 0.75:-0.02:0.2;
M_1 = [1 1 1];
map = M_0'*M_1;
subplot(2,3,1)
NAS_DTB = [Indu_dtbs(:) Indu_dtbs_Adj(:)];
[~,density,X,Y]=kde2d(NAS_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（a）核密度分布（工业）','FontSize',12,'FontName','Songti SC')
subplot(2,3,4); 
contour(X,Y,density,75)
axis([-1 9 -1 9])
hold on 
x=-1:1:9;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
title('（b）密度等高线（工业）','FontSize',12,'FontName','Songti SC')
subplot(2,3,2)
Labor_DTB = [Labor_dtbs(:) Labor_dtbs_Adj(:)]; 
[~,density,X,Y]=kde2d(Labor_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（c）核密度分布（劳动）','FontSize',12,'FontName','Songti SC')
subplot(2,3,5);
contour(X,Y,density,75)
axis([-1 9 -1 9])
hold on 
x=-1:1:9;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
title('（d）密度等高线（劳动）','FontSize',12,'FontName','Songti SC')
subplot(2,3,3)
IN_DTB = [Cap_dtbs(:) Cap_dtbs_Adj(:)];
[~,density,X,Y]=kde2d(IN_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（e）核密度分布（资本）','FontSize',12,'FontName','Songti SC')
subplot(2,3,6); 
contour(X,Y,density,75)
axis([-1 9 -1 9])
hold on 
x=-1:1:9;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省内循环壁垒','FontSize',12,'FontName','Songti SC');
title('（f）密度等高线（资本）','FontSize',12,'FontName','Songti SC')
colormap(map)
set(gcf,'position',[0,0,1200,550],'color','white'); 
fn_III_2 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/figure_III_2.tif';
saveas(gcf,fn_III_2,'tif');

%% 附录IV  中国经济外循环贸易壁垒的空间特征
% 地区层面
figure(3)
clf
M_0 = 0.75:-0.02:0.2;
M_1 = [1 1 1];
map = M_0'*M_1;
subplot(2,3,1)
NA_FTB = [Reg_ftbp(:) Reg_ftbp_Adj(:)]; 
[~,density,X,Y]=kde2d(NA_FTB); 
meshc(X,Y,density) 
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（a）核密度分布（全国）','FontSize',12,'FontName','Songti SC')
subplot(2,3,4); 
contour(X,Y,density,75)
axis([-1 8 -1 8])
hold on 
x=-1:1:8;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（b）密度等高线（全国）','FontSize',12,'FontName','Songti SC')
subplot(2,3,2)
Coa_FTB = [Coa_ftb(:) Coa_ftb_adj(:)]; 
[~,density,X,Y]=kde2d(Coa_FTB); 
meshc(X,Y,density) 
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（c）核密度分布（沿海）','FontSize',12,'FontName','Songti SC')
subplot(2,3,5); 
contour(X,Y,density,75)
axis([-1 8 -1 8])
hold on 
x=-1:1:8;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（d）密度等高线（沿海）','FontSize',12,'FontName','Songti SC')
subplot(2,3,3)
IN_FTB = [In_ftb(:) In_ftb_adj(:)]; 
[~,density,X,Y]=kde2d(IN_FTB); 
meshc(X,Y,density) 
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（e）核密度分布（内陆）','FontSize',12,'FontName','Songti SC')
subplot(2,3,6); 
contour(X,Y,density,75)
axis([-1 8 -1 8])
hold on 
x=-1:1:8;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（f）密度等高线（内陆）','FontSize',12,'FontName','Songti SC')
colormap(map)
set(gcf,'position',[0,0,1200,550],'color','white'); 
fn_IV_1 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/figure_IV_1.tif';
saveas(gcf,fn_IV_1,'tif');

% 部门层面 
figure(4)
clf
M_0 = 0.75:-0.02:0.2;
M_1 = [1 1 1];
map = M_0'*M_1;
subplot(2,3,1)
NAS_FTB = [Indu_ftbs(:) Indu_ftbs_Adj(:)];
[~,density,X,Y]=kde2d(NAS_FTB); 
meshc(X,Y,density) 
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（a）核密度分布（工业）','FontSize',12,'FontName','Songti SC')
subplot(2,3,4); 
contour(X,Y,density,75)
axis([-1 15 -1 15])
hold on 
x=-1:1:15;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（b）密度等高线（工业）','FontSize',12,'FontName','Songti SC')
subplot(2,3,2)
Labor_FTB = [Labor_ftbs(:) Labor_ftbs_Adj(:)]; 
[~,density,X,Y]=kde2d(Labor_FTB); 
meshc(X,Y,density) 
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（c）核密度分布（劳动）','FontSize',12,'FontName','Songti SC')
subplot(2,3,5); 
contour(X,Y,density,75)
axis([-1 15 -1 15])
hold on 
x=-1:1:15;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（d）密度等高线（劳动）','FontSize',12,'FontName','Songti SC')
subplot(2,3,3)
IN_FTB = [Cap_ftbs(:) Cap_ftbs_Adj(:)]; 
[~,density,X,Y]=kde2d(IN_FTB); 
meshc(X,Y,density) 
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（e）核密度分布（资本）','FontSize',12,'FontName','Songti SC')
subplot(2,3,6);
contour(X,Y,density,75)
axis([-1 15 -1 15])
hold on 
x=-1:1:15;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年邻省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（f）密度等高线（资本）','FontSize',12,'FontName','Songti SC')
colormap(map)
set(gcf,'position',[0,0,1200,550],'color','white'); 
fn_IV_2 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/figure_IV_2.tif';
saveas(gcf,fn_IV_2,'tif');

%% 附录V  中国经济双循环贸易壁垒的对比分析及关联效应
%% 贸易壁垒的对比
Compare_region = DTB_CI(:,3:7)./FTB_CI;  % 地区层面的比较
TCR = [Compare_region mean(Compare_region,2)];
TCR = round(TCR,2);
Compare_sector = DTB_LC(:,3:7)./FTB_LC;  % 部门层面的比较
TCS = [Compare_sector mean(Compare_sector,2)];
TCS = round(TCS,2);
CP = [TCR;TCS];
IntraColname = {'全国';'沿海地区';'内陆地区';'工业';'劳动密集型部门';'资本密集型部门'};
VarnameR ={'1997','2002','2007','2012','2017','均值'}; 
Table_V_1 = table(CP(:,1),CP(:,2),CP(:,3),CP(:,4),CP(:,5),CP(:,6),'RowNames',IntraColname,'VariableNames',VarnameR);
tname_V_1 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/table_V_1.csv';
writetable(Table_V_1, tname_V_1,'WriteRowNames',true);

%% 双循环壁垒的空间关联
% 地区层面 
ReL_dtb = Reg_dtbp(:,3:7);
Rel_ftb = Reg_ftbp;
Coal_dtb = Coa_dtb(:,3:7);
Coal_ftb = Coa_ftb;
Inl_dtb = In_dtb(:,3:7);
Inl_ftb = In_ftb;
figure(5)
clf
M_0 = 0.75:-0.02:0.2;
M_1 = [1 1 1];
map = M_0'*M_1;
subplot(2,3,1)
NA_DTB = [ReL_dtb(:) Rel_ftb(:)];
[~,density,X,Y]=kde2d(NA_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（a）核密度分布（全国）','FontSize',12,'FontName','Songti SC')
subplot(2,3,4); 
contour(X,Y,density,75)
axis([-1 10 -1 10])
hold on 
x=-1:1:10;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（b）密度等高线（全国）','FontSize',12,'FontName','Songti SC')
subplot(2,3,2)
Coa_DTB = [Coal_dtb(:) Coal_ftb(:)]; 
[~,density,X,Y]=kde2d(Coa_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（c）核密度分布（沿海）','FontSize',12,'FontName','Songti SC')
subplot(2,3,5);
contour(X,Y,density,75)
axis([-1 10 -1 10])
hold on 
x=-1:1:10;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（d）密度等高线（沿海）','FontSize',12,'FontName','Songti SC')
subplot(2,3,3)
IN_DTB = [Inl_dtb(:) Inl_ftb(:)]; 
[~,density,X,Y]=kde2d(IN_DTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（e）核密度分布（内陆）','FontSize',12,'FontName','Songti SC')
subplot(2,3,6); 
contour(X,Y,density,75)
axis([-1 10 -1 10])
hold on 
x=-1:1:10;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（f）密度等高线（内陆）','FontSize',12,'FontName','Songti SC')
colormap(map)
set(gcf,'position',[0,0,1200,550],'color','white'); 
fname_V_1 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/figure_V_1.tif';
saveas(gcf,fname_V_1,'tif');

% 部门层面 
Sel_dtb = Indu_dtbs(:,3:7);
Sel_ftb = Indu_ftbs;
Labl_dtb = Labor_dtbs(:,3:7);
Labl_ftb = Labor_ftbs;
Cap_dtb = Cap_dtbs(:,3:7);
Cap_ftb = Cap_ftbs;
figure(6)
clf
M_0 = 0.75:-0.02:0.2;
M_1 = [1 1 1];
map = M_0'*M_1;
subplot(2,3,1)
NAS_FTB = [Sel_dtb(:) Sel_ftb(:)];
[~,density,X,Y]=kde2d(NAS_FTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（a）核密度分布（工业）','FontSize',12,'FontName','Songti SC')
subplot(2,3,4);
contour(X,Y,density,75)
axis([-1 15 -1 15])
hold on 
x=-1:1:15;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（b）密度等高线（工业）','FontSize',12,'FontName','Songti SC')
subplot(2,3,2)
Labor_FTB = [Labl_dtb(:) Labl_ftb(:)]; 
[~,density,X,Y]=kde2d(Labor_FTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（c）核密度分布（劳动）','FontSize',12,'FontName','Songti SC')
subplot(2,3,5); 
contour(X,Y,density,75)
axis([-1 15 -1 15])
hold on 
x=-1:1:15;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（d）密度等高线（劳动）','FontSize',12,'FontName','Songti SC')
subplot(2,3,3)
IN_FTB = [Cap_dtb(:) Cap_ftb(:)];
[~,density,X,Y]=kde2d(IN_FTB); 
meshc(X,Y,density) 
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
zlabel('概率密度','FontSize',12,'FontName','Songti SC');
title('（e）核密度分布（资本）','FontSize',12,'FontName','Songti SC')
subplot(2,3,6); 
contour(X,Y,density,75)
axis([-1 15 -1 15])
hold on 
x=-1:1:15;
y=x;
plot(x,y,'--k');
hold off
xlabel('t年本省内循环壁垒','FontSize',12,'FontName','Songti SC');
ylabel('t年本省外循环壁垒','FontSize',12,'FontName','Songti SC');
title('（f）密度等高线（资本）','FontSize',12,'FontName','Songti SC')
colormap(map)
set(gcf,'position',[0,0,1200,550],'color','white');
fname_V_2 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/figure_V_2.tif';
saveas(gcf,fname_V_2,'tif');