How to do multiple saves during a loop?
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to write a code into my script that will create an output .jpg for each of my .mat outputs. However it seems to only produce one .jpg because it overwrites each one. My code is listed below. Any help would be great.
Code:
%%Apply angle correction to rectified tranmittance corrected thermal images
% Calculate orientation angle for cells in dem
cd('C:\Users\anson_000\Documents\MATLAB\EMCT_Aug12\Rectified_thermal_im')
list=dir('*.mat');
% Calculate viewing distance components and angle vectdist_x = x0-Xdem; vectdist_y = y0-Ydem; vectdist_z = z0-Zdem; cosang = -(vectdist_x.*theta + vectdist_y.*phi + vectdist_z ) ./ ... ( sqrt( theta.^2+phi.^2+1 ) .* sqrt(vectdist_x.^2+vectdist_y.^2+vectdist_z.^2) );
cosang( cosang<0 ) = NaN;
for zz=1:length(list)
filename=list(zz).name;
output_name=['Temp_fullcorr_' filename(12:24)];
load(list(zz).name);
rect_rad_image = Rect_Planck_radconvers(10.25e-6,tempK_rect);
rad_rect_corrected = NaN*rect_rad_image;
temp_rect_corrected = NaN*tempK_rect;
hot_px = tempK_rect > 312; %Value in K?
rad_rect_corrected(hot_px)=rect_rad_image(hot_px)./cosang(hot_px);
temp_rect_corrected(hot_px)=tempK_rect(hot_px)./(cosang(hot_px).^(1/4));
save(output_name, 'temp_rect_corrected');
% Write an image to show the area identified as hot (white)
imwrite( uint8( cat(3, hot_px, hot_px, hot_px)*255 ), 'image_name.jpg', 'Quality', 100)
end
댓글 수: 0
채택된 답변
Orion
2014년 12월 9일
I guess all your .jpg are named image_name.jpg ?
Inside the loop, you coded :
imwrite( uint8( cat(3, hot_px, hot_px, hot_px)*255 ), 'image_name.jpg', 'Quality', 100)
so the name is unchanged during the loop.
make something like :
MyImageName = sprintf('image_name%d.jpg',zz);
imwrite( uint8( cat(3, hot_px, hot_px, hot_px)*255 ), MyImageName , 'Quality', 100)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!