





% 获取当前目录下的所有txt文件
files = dir('*.txt');
numFiles = length(files);
% 准备一个图形窗口
figure;
% 定义一组颜色,用于不同的线条
colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']; % 红、绿、蓝、青、品红、黄、黑
% 遍历所有文件
for k = 1:numFiles
% 读取文件名
filename = files(k).name;
% 读取数据,忽略前四行
fileID = fopen(filename, 'r');
% 跳过前四行
for i = 1:4
fgetl(fileID);
end
% 读取剩余的数据
data = textscan(fileID, '%f%f', 'Delimiter', ' ', 'MultipleDelimsAsOne', true);
fclose(fileID);
% 提取光谱标签和光谱响应
wavelengths = data{1};
responses = data{2};
% 绘制光谱图,使用不同的颜色
plot(wavelengths, responses, 'Color', colors(mod(k-1, length(colors))+1));
hold on; % 保持图像,以便在同一个图上绘制所有光谱
end
set(gca, 'LineWidth', 2);
set(gca, 'FontName', 'Times New Roman', 'FontSize', 16, 'FontWeight', 'bold');
xlabel('Wavelength', 'FontName', 'Times New Roman', 'FontSize', 16);
ylabel('Response', 'FontName', 'Times New Roman', 'FontSize', 16);
% 关闭hold状态
hold off;