最近遇到了个批处理的问题,自己尝试用matlab解决了,代码如下,希望以后自己用得到:
filepath = 'C:\Users\MZ\Desktop\file1\';
spec = zeros(501,8);
for num = 10:2:24
filename = num2str(num,'%d-1-0.CSV');
filenameA = fullfile(filepath, filename);
fid = fopen(filenameA,'rb');
matrix = readmatrix(filenameA);
lambda = matrix(241:1:741,1);
spectrum = mapminmax(matrix(241:1:741,2), 0, 1);
for a = 1:501
spec(a,num/2-4) = spectrum(a);
end
end
%write to txt
fid = fopen(['C:\Users\MZ\Desktop\file1\', 'data.txt'], 'w');
[r,c] = size(spec);
for i = 1:r
fprintf(fid, '%f\t', lambda(i));
for j = 2:c+1
fprintf(fid,'%f\t', spec(i,j-1));
end
fprintf(fid,'\r\n');
end
fclose(fid);