参考链接:
使用MATLAB遍历文件
strtrim用法
strsplit用法
cell单元数据使用{}
close all;
dir_path = 'C:/Users/';
fileFolder = ls(dir_path);
fileNum = length(fileFolder(:,1)) - 2;
for i = 3:(3+fileNum-1)file_path = strcat(dir_path, strtrim(fileFolder(i,:)));fid = fopen(file_path, 'rb');s = strsplit(strtrim(fileFolder(i,:)),'_');c1 = str2_double(s{length(s)-2});c2 = str2_double(s{length(s)-3});data_length = c1 * c2;A = fread(fid, data_length);[N, X] = hist(A, 256);x = 1:1:256;f = figure;plot(x, N);title(strtrim(fileFolder(i,:)));grid on;save_path = strcat(dir_path, strtrim(fileFolder(i,:)),'.fig');savefig(save_path);fclose(fid);hold on;
end
close all;