Change element of a matrix in a row

1 次查看(过去 30 天)
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!
  2 个评论
Jan
Jan 2016-11-3
Please explain the procedure: Do you want to the rows to be filled by 1s between the first and the lase 1?
Selim Karakurt
Selim Karakurt 2016-11-3
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!

请先登录,再进行评论。

回答(2 个)

KSSV
KSSV 2016-11-3
编辑:KSSV 2016-11-3
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
  6 个评论
Selim Karakurt
Selim Karakurt 2016-11-3
编辑:Selim Karakurt 2016-11-3
for example something like this. all i want is to fill the picture with black.

请先登录,再进行评论。


Thorsten
Thorsten 2016-11-4
编辑:Thorsten 2016-11-4

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by