Problem 32. Most nonzero elements in row
Solution Stats
Problem Comments

11 Comments
How am I wrong here?
"a = [ ...
1 0 0;
0 0 0;
0 0 0;
0 0 0;
0 2 3];
r_correct = 5;"
My code says 2, I think it's correct, what am I missing?
It wants the number of the row with the most nonzeros.
Thank you Tim! I feel like a fool, but that'll teach me to read the requirements more carefully. Hopefully.
Great Problem!
nice
Love this one
Piece of cake
nice
easy :) but nice
Could you please check my solution.
How come the solution example 2, 3 and 4 have r= 3, 5 and 4. When it should have been r = 4, 3 and 1.
As these are the maximum number of zeros in any of the given row.
Can someone please give me a hint on how the solutions are provided so different?
What are these matrices in last 3 test cases? Can someone help
Solution Comments

1 Comment
This problem is not difficult. But we still need to be careful

2 Comments
Nice solution!
nice solution!!

1 Comment
so happy~

2 Comments
there is a bug i the code
input a = [1 0 1 1 ; 9999 0 0 0]
output 2
there is a bug in the code
input a = [1 0 1 1 ; 9999 0 0 0]
output 2

1 Comment
r = max(sum((a==0)'));

1 Comment
Original solution I created by digging through documentation was x=a~=0; y=sum(x,2); [M,I]=max(y); r=max(y). Solution had a size of 31 so I compressed it into it's current version.

1 Comment
in case number 3 and 4 total number of element is also less than your correct fullest row output
How does this thing is possible

1 Comment
I did it!
(^^;)

1 Comment
this is a terrible solution, someone help.

1 Comment
Could you tell me how you did it?

1 Comment
Once again ive used a for loop only because it seems so much simpler. The more I do these I see how each person has a different approach to a problem which I think is very cool. Thanks for the problem!

1 Comment
test suite is not ok

2 Comments
what is the problem here ? it works on matlab and gives the correct row
2 things: You forgot to set your output (so add a line r=ix, or change the r in the first line into ix.
and you changed the function name so it doesn't recognize it.
Your solution does work.

1 Comment
Well done.

2 Comments
Is there any way to avoid this for loop??
Yes, a hint: compare with zeros matrix and count (sum) the nonzero elements in this logical matrix.

1 Comment
looks very strange

2 Comments
I can't believe I used a trick I learned from Javascript...
I tried to optimize my solution as much possible as I could, still my code size was 45, any idea what would be there in the leading solution of this problem which has code size as 11 ? Which trick did you use?
Problem Recent Solvers6692
Suggested Problems

35514 Solvers

The Hitchhiker's Guide to MATLAB
3142 Solvers

Back to basics 3  Temp Directory
358 Solvers

330 Solvers

664 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!