% 单个chron
chron = arrayfun(@(ii) readmatrix(fullfile(file(ii).folder,file(ii).name),'NumHeaderLines',1),...
    3:length(file),'UniformOutput', false);
% 合并chron
sampWithDate = mergeDFbyRownames(chron{1}(:,1:2),chron{2}(:,1:2));
for ii = 3:length(chron)
    sampWithDate = mergeDFbyRownames(sampWithDate,chron{ii}(:,1:2));
end

sampWithDate_seg = sampWithDate(sampWithDate(:,1)>=1982 & sampWithDate(:,1)<=2000, 2:end);
[eofs,pcs,expl] = pca(sampWithDate_seg,'VariableWeights','variance','NumComponents',1);

[r,p] = deal([]);
for ii = 1:size(tws_seg,1)
    for jj = 1:size(tws_seg,2)
        t = squeeze(tws_seg(ii,jj,:)); 
        [r(ii,jj),p(ii,jj)] = corr((t),(pcs));
    end
end

figure
imagescn(Lon,Lat,r); hold on
caxis([-0.6,0.6])
cmocean('balance','pivot',0)
%stipple(Lon,Lat,(r>0 & p<0.02),'markersize',5,'density',100) 

   % 获取显著性位置并添加白色星号
    [r_idx, c_idx] = find(r > 0 & p < 0.01);
    for i = 1:length(r_idx)
        lon_val = double(Lon(r_idx(i), c_idx(i)));  % 确保经度是double类型
        lat_val = double(Lat(r_idx(i), c_idx(i)));  % 确保纬度是double类型
        text(lon_val, lat_val, '*', 'Color', [1 1 1], 'FontSize', 12, 'HorizontalAlignment', 'center');
    end