close all
addpath(genpath('D:\em3d_MT\bin'));
load('FWD_2layer-sig2000-20000-epsr8-856-aD45','data');
RMT1Dexmple_ani_Esp_aD45_ChenHuang;


comp={'rhoXY';'rhoYX';'phaXY';'phaYX'};
% comp={'Ex1';'Ey2';'Hy1';'Hx2'};

comparedata(data1,data,comp,@abs);
set(gcf,"Position",[500 0 400 700]);

%

function comparedata(data1,data2,comp,F)
ncom = size(comp,1);
figure;

for ii = 1:ncom
    compn = cell2mat(comp(ii));
    err = F(data1(:,compn).Variables)-F(data2(:,compn).Variables);
    subplot(ncom,1,ii);

    plot(data1.Frequency,F(data1(:,compn).Variables),'-','LineWidth',1.5);
    hold on;
    p1=plot(data2.Frequency,F(data2(:,compn).Variables),'^','LineWidth',1.5,MarkerSize=5);
    col1=get(p1,'Color');
    set(p1,MarkerFaceColor=col1);
    % hold on;
    % errorbar(data2.Frequency,F(data2(:,compn).Variables),err,'|','LineWidth',1.5,'Color',col1);


    if ismember(comp(ii),{ 'rhoXY' } )
        ylabel(['\rho_{xy}' '(ohm.m)'],"FontSize",14,"FontWeight","bold");
        set(gca,'YScale','log','YTick',[1000 10000]);
    elseif ismember(comp(ii),{'rhoYX'  } )
        ylabel(['\rho_{yx}' '(ohm.m)'],"FontSize",14,"FontWeight","bold");
        set(gca,'YScale','log','YTick',[1000 10000]);
    elseif ismember(comp(ii),{'phaXY' } )
        ylabel(['\phi_{xy}' '(°)'],"FontSize",14,"FontWeight","bold");
    elseif ismember(comp(ii),{'phaYX'  } )
        ylabel(['\phi_{yx}' '(°)'],"FontSize",14,"FontWeight","bold");
    end

    set(gca,'XScale','log','LineWidth',1.5,"FontSize",10,'FontWeight','bold');

    if ii==1
        legend(['RMT1D';'RMT3D';'Error'],'box','off',"FontWeight","bold");

    end
end
xlabel('Frequency(Hz)','FontWeight','bold');
end