Problem 307. First non-zero element in each column
For a given matrix, calculate the index of the first non-zero element in each column. Assuming a column with all elements zero is not permitted.
Example:
in->x = [0 1 0 0;
4 3 7 0;
0 0 2 6;
0 9 0 5];
out->i = [2 1 2 3]; % row numbers
Solution Stats
Problem Comments
-
2 Comments
Ned Gulley
on 5 Apr 2012
I fixed the test. There was no assert statement.
Dyuman Joshi
on 29 Oct 2021
Test cases have been added.
Solution Comments
Show commentsProblem Recent Solvers928
Suggested Problems
-
Remove all the words that end with "ain"
2615 Solvers
-
Replace NaNs with the number that appears to its left in the row.
3055 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
639 Solvers
-
Construct an index vector from two input vectors in vectorized fashion
442 Solvers
-
Create matrix of replicated elements
393 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!