function [welfare_all,welfare_dtb,welfare_ftb] = wel2(NEX,TB,ela,ls,n)
BTRADE = NEX;        %961*17
BTB = TB;       %961*17
ELA = ela;                 %17*1
ELA(7)=5;
LS = ls;        %17*30
welfare_all = zeros(30,17);
welfare_dtb = zeros(30,17);
welfare_ftb = zeros(30,17);
% 双循环贸易壁垒变动
for i=1:1:17
    % 双循环贸易壁垒变动
    BEX_Sector = reshape(BTRADE(:,i),31,31);  %双边贸易额 31*31
    BTB_Sector = reshape(BTB(:,i),31,31);     %双边贸易壁垒 31*31
    ELAS = ELA(i);                            %特定部门弹性 1*1
    LSS_0 = LS(i,:);                          %特定部门劳动投入份额 1*30
    LSS = [LSS_0 0];
    tua_dtb = n.*BTB_Sector;
    tua_dtb(tua_dtb==0)=1;
    W_hat = wel1(BEX_Sector,tua_dtb,ELAS,LSS);
    welfare_all(:,i)=W_hat(1:30,:);
    % 内循环贸易壁垒变动
    BEX_Sector = reshape(BTRADE(:,i),31,31);  %双边贸易额 31*31
    BTB_Sector = reshape(BTB(:,i),31,31);     %双边贸易壁垒 31*31
    ELAS = ELA(i);                            %特定部门弹性 1*1
    LSS_0 = LS(i,:);                          %特定部门劳动投入份额 1*30
    LSS = [LSS_0 0];
    tua_dtb = n.*BTB_Sector;
    tua_dtb(31,:)=1;
    tua_dtb(:,31)=1;
    tua_dtb(tua_dtb==0)=1;
    W_hat = wel1(BEX_Sector,tua_dtb,ELAS,LSS);
    welfare_dtb(:,i)=W_hat(1:30,:);
    % 外循环贸易壁垒变动
    BEX_Sector = reshape(BTRADE(:,i),31,31);  %双边贸易额 31*31
    BTB_Sector = reshape(BTB(:,i),31,31);     %双边贸易壁垒 31*31
    ELAS = ELA(i);                            %特定部门弹性 1*1
    LSS_0 = LS(i,:);                          %特定部门劳动投入份额 1*30
    LSS = [LSS_0 0];
    tua_ftb = n.*BTB_Sector;
    tua_ftb(1:30,1:30)=1;
    tua_ftb(tua_ftb==0)=1;
    W_hat = wel1(BEX_Sector,tua_ftb,ELAS,LSS);
    welfare_ftb(:,i)=W_hat(1:30,:);
end
welfare_all(isinf(welfare_all))=1;
welfare_dtb(isinf(welfare_dtb))=1;
welfare_ftb(isinf(welfare_ftb))=1;
end