史-长度高度
A = cell(10,1);
[A_a,A_b] = size(A);
fpa = 'L:\20190627\第三道\'; %%全部数据
A1 = cell(10,1);
[A1_a,A1_b] = size(A1);
fpa_num = 'L:\20190627长度高度信息\第三道\'; %%全部数据
name = dir(fpa);%将温度场9-12中的文件列表读入
nameA1 = dir(fpa_num);%将温度场9-12中的文件列表读入
col = 1;
row =1;
fpath1='L:\20190627-num\第三道\';%mat%%保存地址
for id = 3:length(name)
wholename=strcat(fpa,name(id).name,'\');
A(row,col) = cellstr(wholename);
wholenameA1=strcat(fpa_num,nameA1(id).name);
A1(row,col) = cellstr(wholenameA1);
row = row+ 1;
end %将温度场9-12中的文件完整命名并存入A的元胞数组中20*1
total_i = 2;
i1 = 1;
for test_i = 1:A_a
test_fpath = A(test_i,:);
fpa_char = cell2mat(test_fpath);
end_fpa_0 = length(fpa_char);
fpa_char_file = fpa_char(end_fpa_0-2:end_fpa_0);
fpa_ind = strcat(fpath1,fpa_char_file);
if ~exist(fpa_ind,'dir')
mkdir(fpa_ind);
end
fpa_image = strcat(fpa_ind,'image\');
if ~exist(fpa_image,'dir')
mkdir(fpa_image);
end
fpa_txt = strcat(fpa_ind,'txt\');
if ~exist(fpa_txt,'dir')
mkdir(fpa_txt);
end
test_name = dir(fpa_char);%依次读入元胞数组中的文件夹下的图片文件
%%%%%加载mat并同时读取里面的内容,转成struct即可
test_mat = A1(test_i,:);
fmat_char = cell2mat(test_mat);
fmat_struct = struct2cell(load(fmat_char));%读入mat文件
mat_num = cell2mat(fmat_struct);
[test_a,test_b] = size(mat_num);
for test_name_i =3:length(test_name)
test_file_name = test_name(test_name_i).name;%依次读入图片文件名
end_0 = length(test_file_name);
imgname_p = test_file_name(1:4);%截取图片文件名的数据部分如0060
%imgname_p=strrep(test_file_name,'.tiff','');
imgname_txt = strrep(test_file_name,'bmp','txt');
cc = str2double(imgname_p);
%截取的图片文章名是字符串,用str2double函数把字符串转化成数值才可与mat文件中的数据对应
test_wholename=strcat(cell2mat(test_fpath),test_file_name);%字符串连接函数
if isnan(cc)%isnan是一个全局方法,用来检查一个值是否能被number()成功替换
fprintf('None of the values are matching');
break;
else
image = imread(test_wholename);
%imshow(mat,[]);
for test_a_i = 1:test_a
cc1 = mat_num(test_a_i,1);
if (cc == cc1)
txt = mat_num(test_a_i,3);
filePath = strcat(fpa_image,test_file_name);%图片保存地址;
filePath2 = strcat(fpa_txt,imgname_txt);
wholename2=sprintf('%s',filePath);
imwrite(image,wholename2);
fid=fopen(filePath2,'wt');
fprintf(fid,'%.4f',txt);
fclose(fid);%关闭文件。
end
end
end
end
end