MATLAB: Loop code for images to plot graph

loop

Hey, I have a code to read my B&W images and convert it to a graph. Now i have several hundreds images and was wondering if anyone could help me with a loop function to make my life easier.
The code is below, thanks in advance.
function blackwhite
pix = 768*1024 % number of pixels in each image
A1= 100*(sum(sum(imread('1.tif'))/255)/pix); % percent of white pixels in image 1 A2= 100*(sum(sum(imread('2.tif'))/255)/pix); A3= 100*(sum(sum(imread('3.tif'))/255)/pix); A4= 100*(sum(sum(imread('4.tif'))/255)/pix); A5= 100*(sum(sum(imread('5.tif'))/255)/pix); A6= 100*(sum(sum(imread('6.tif'))/255)/pix); A7= 100*(sum(sum(imread('7.tif'))/255)/pix); A8= 100*(sum(sum(imread('8.tif'))/255)/pix); A9= 100*(sum(sum(imread('9.tif'))/255)/pix); A10= 100*(sum(sum(imread('10.tif'))/255)/pix); A11= 100*(sum(sum(imread('11.tif'))/255)/pix); A12= 100*(sum(sum(imread('12.tif'))/255)/pix); A13= 100*(sum(sum(imread('13.tif'))/255)/pix); A14= 100*(sum(sum(imread('14.tif'))/255)/pix); A15= 100*(sum(sum(imread('15.tif'))/255)/pix); A16= 100*(sum(sum(imread('16.tif'))/255)/pix); A17= 100*(sum(sum(imread('17.tif'))/255)/pix); A18= 100*(sum(sum(imread('18.tif'))/255)/pix); A19= 100*(sum(sum(imread('19.tif'))/255)/pix); A20= 100*(sum(sum(imread('20.tif'))/255)/pix); A21= 100*(sum(sum(imread('21.tif'))/255)/pix); A22= 100*(sum(sum(imread('22.tif'))/255)/pix);
A= [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22]; time= [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600, 630];
plot(time,A) xlabel('time minutes') ylabel('%white')
end

Best Answer

N = 22; % Number of images
pix = 768*1024; % number of pixels in each image
A = zeros(N,1); % preallocation
for k = 1:N
A(k) = 100*(sum(sum(imread([num2str(k) '.tif']))/255)/pix);
end
time = 0:30:(N-1)*30;
Related Question