%count how many malignant tumors in a given data file 

tum=dlmread('tumor1.txt')  %read the data

%find the row and column in the data array
sz=size(tum)  %dimensioanl size
row=sz(1)     %number of rows  
col=sz(2)     %number of columns

%count how many left bend
count_left_bend=0;
for i=[1:row-1]
    for j=[1:col-1]
       if (tum(i,j) == 1 && tum(i,j+1)==1 && tum(i+1,j)==1) 
           count_left_bend=count_left_bend+1;
       end
    end
end

disp('Number of left_bend=')
count_left_bend


%count how many right bend
count_right_bend=0;
for i=[1:row-1]
    for j=[1:col-1]
       if (tum(i,j) == 1 && tum(i,j+1)==1 && tum(i+1,j+1)==1) 
           count_right_bend=count_right_bend+1;
       end
    end
end

disp('Number of right_bend=')
count_right_bend

%find the number of malignant tumors
count_malig=count_left_bend + count_right_bend;
disp('Number of malignant tumors=')
count_malig





