代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。