加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
join_LIU_NPX.m 3.01 KB
一键复制 编辑 原始数据 按行查看 历史
NPXFL=dir('NPX_0930_*.pdf');
LIUFL=dir('LIU_0930_*.pdf');
checkPatternMatch({LIUFL.name},{NPXFL.name});
batchRename({LIUFL.name},{NPXFL.name});
function batchRename(series1Files, series2Files, pathToFiles)
% Assuming file names are provided without full path; adjust as needed
if nargin < 3 || isempty(pathToFiles)
pathToFiles = pwd; % Default to current working directory
end
% Extract #1 and #2, assuming the rest of the code from `checkPatternMatch` applies
[s1_chan, s1_time] = extractNumbers(series1Files);
[s2_chan, s2_time] = extractNumbers(series2Files);
% Find common pairs and sort them for prefix assignment
commonPairs = intersect([s1_chan; s1_time].', [s2_chan; s2_time].', 'rows');
[~, sortedIdx] = sort(commonPairs(:,1)); % Sort by #1, then implicitly by #2 due to stability
sortedCommonPairs = commonPairs(sortedIdx, :);
% Assign and prepend incremental prefix
for i = 1:size(sortedCommonPairs, 1)
pairChan = sortedCommonPairs(i, 1);
pairTime = sortedCommonPairs(i, 2);
% Find files matching the current pair in both series
idxS1 = find((s1_chan == pairChan) & (s1_time == pairTime));
idxS2 = find((s2_chan == pairChan) & (s2_time == pairTime));
originalLiuName = series1Files{idxS1};
originalNPXName = series2Files{idxS2};
% Construct new name with prefix
newLiuName = sprintf('%03d_%s', i, originalLiuName);
newNPXName = sprintf('%03d_%s', i, originalNPXName);
% Perform renaming (comment out for dry-run or adjust path as necessary)
movefile(fullfile(pathToFiles, originalLiuName), fullfile(pathToFiles, newLiuName));
movefile(fullfile(pathToFiles, originalNPXName), fullfile(pathToFiles, newNPXName));
% fprintf('Renamed %s to %s\n', originalName, newName);
end
end
function mismatch = checkPatternMatch(series1Names, series2Names)
% Extract #1 and #2 from file names into matrices
[s1_chan, s1_time] = extractNumbers(series1Names);
[s2_chan, s2_time] = extractNumbers(series2Names);
% Combine into pairs for easy comparison
s1_pairs = [s1_chan; s1_time].';
s2_pairs = [s2_chan; s2_time].';
% Check for mismatches (pairs in s1 not found in s2)
mismatch = setdiff(s1_pairs, s2_pairs, 'rows');
if isempty(mismatch)
disp('All patterns are matched between the two series.');
mismatch = logical(0); % Return false to indicate no mismatch
else
disp('Mismatched pairs (Series 1):');
display(mismatch);
mismatch = logical(1); % Return true to indicate there's a mismatch
end
end
% Helper function to extract #1 and #2 from file name series
function [chan, time] = extractNumbers(fileNames)
expressions = {'chan(\d+)','time(\d+)'};
tokens = regexp(fileNames, sprintf('%s|%s', expressions{:}), 'tokens');
chan = str2double(cellfun(@(x) x{1}, tokens));
time = str2double(cellfun(@(x) x{2}, tokens));
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化