MATLAB: Output matrix in for loop is not outputting full matrix properly

for loopmatrix arrayoutput

My code is bellow. I am having issues with my edges output matrix. The matrix values should output a string of 8 independent numbers based on what the for loop is telling it to do, but instead it is either outputing just the final answer for a vector like this [840 0 0 0 0 0 840] where 840 is the final answer in the loop. Any suggestions?
image = imread('x10.pic.1.rev1.bmp');
matrix_size = size(image);
image_length = matrix_size(1);
image_width = matrix_size(2);
i = 1 : image_length;
j = 1 : image_width;
row_matrix=image(1,j,1);
row_matrix(1,j)
for n = 1: image_width
if row_matrix(1,n) < 250
row_matrix(1,n) = 255;
else
row_matrix(1,n) = 0;
end;
end
data_row = row_matrix;
kedges=0;
for k = 1: length(data_row)-1
if abs(data_row(k+1)- data_row(k)) > 0
edges=k
kedges=kedges+1
edges(1:kedges)=k
end;
end;
%for p = 1: size(edges(2))
%particle_length= edges(2p)-edges(2p-1);
%end

Best Answer

edges=k overwrites all of the edges matrix to become the scalar value "k", throwing away everything that was there before.
Related Question