Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Find 1's each Row

Asked by Hello kity on 30 Jan 2013

I have an easy question;

I have a matrix ( x row, x columns) filled with 0s and 1s.

I want to check if there is a 1 in every row (for every column).

then result that in a new matrix

so basically it is this

0 0 0 = 0
1 0 0 = 1
0 1 0 = 1
0 0 1 = 1 


Jan Simon on 30 Jan 2013

What should happen for [1,1,0] and [1,1,1]?

Image Analyst on 30 Jan 2013

Not that it matters, but you don't have x rows and x columns - your matrix is not square. Plus your answer does not check for a 1 in every row for every column. That would be an array that is completely all 1's. You don't even check for 1's in every column. You're just checking each row if there is a 1, which is quite different. Plus we don't even know if you need exactly one 1, or if multiple 1's should also produce a 1 for that row in your output vector.

Hello kity on 30 Jan 2013

I can only get a single 1 at each row, that is how my data is buildup.

Hello kity


No products are associated with this question.

1 Answer

Answer by Image Analyst on 30 Jan 2013
Accepted answer
oneInColumn = any(yourMatrix, 2);


Image Analyst

Contact us