# Change element of a matrix in a row

2 views (last 30 days)
Selim Karakurt on 3 Nov 2016
Edited: Thorsten on 4 Nov 2016
Hello community,
I am using matlab for image processing. I filter the image and get a black-white image and after that i want to count them. I finished that. The problem is that in the Matrix there are white places. For better understanding i gave you an example.
A
0 0 0 0 0
1 0 1 0 0
0 1 0 0 1
1 1 1 1 0
1 0 0 0 1
the result should be
A
0 0 0 0 0
1 1 1 0 0
0 1 1 1 1
1 1 1 1 0
1 1 1 1 1
I can't code it so please i need your help. I hope you can help me.
Thanks!
Jan on 3 Nov 2016
Please explain the procedure: Do you want to the rows to be filled by 1s between the first and the lase 1?
Selim Karakurt on 3 Nov 2016
JES! I tried to give an example. But KSSV answer was good but it dont work because i have to change my logical matrix in to a double matrix. but when i do so my double matrix is filled with only 1 and i loose my information. you can look down what i talked with him. Thanks!

KSSV on 3 Nov 2016
Edited: KSSV on 3 Nov 2016
A = [0 0 0 0 0
1 0 1 0 0
0 1 0 0 1
1 1 1 1 0
1 0 0 0 1 ] ;
B = A ;
[m,n] = size(A) ;
for i = 1:m
idx = find(A(i,:)==1) ;
if ~isempty(idx)
B(i,idx(1):idx(end)) = 1 ;
end
end
B
Selim Karakurt on 3 Nov 2016
Edited: Selim Karakurt on 3 Nov 2016
for example something like this. all i want is to fill the picture with black.
Selim Karakurt on 4 Nov 2016
Nobody there to help me?

Thorsten on 4 Nov 2016
Edited: Thorsten on 4 Nov 2016
help imfill