Binary table - counting bits in rows
Mostrar comentarios más antiguos
Hi,
How can I print only the rows that have only two '1' bits in rows? like this one:
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
Thanks, Henry
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 15 de Sept. de 2015
Do you have the Image Processing Toolbox? If so, it's simple to just call regionprops on each row and measure the lengths of all 1 segments. If any of the lengths = 2, then print that row with fprintf(), like this untested code:
for row = 1 : rows
thisRow = m(row, :);
labeledData = bwlabel(thisRow); % Identify each separate segment.
measurements = regionprops(labeledData, 'Area');
allLengths = [measurements.Area];
% See if any of the stretches of 1's are 2 in length
if any(allLengths == 2)
fprintf('%d ', thisRow);
fprintf('\n');
end
end
1 comentario
Henry Buck
el 15 de Sept. de 2015
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!