
global A C k b x result

%disp("reading image"); fflush(1);
C=imread("comparagram.bmp");
imshow(C);
%C=[1,1,0,0;0,1,0,0;0,0,1,0;0,0,0,2];
n=size(C,1);
A=zeros(n*n,n);
x=zeros(n,1);
k=4;
b=zeros(n*n,1);
disp("creating system of equations"); fflush(1);
for i=1:n
  count = 0;
  total = 0;
  for j=1:n
     count = count+C(i,j); 
     total = total +j* C(i,j);
  end
  x(i) = total/count;
  i % show it
  fflush(1);
end
%b=b.*k;
% now Ax=b

%solve it
%disp("solving..."); fflush(1);
%x=A\b
%fflush(1);
x
% show soln
disp("showing result"); fflush(1);
result=zeros(n);
for i=1:n
  if ((x(i)>=1)&&(x(i)<=n))
    result(i,x(i))=255;
  end%if
end%for
imshow(result);

