Find the index of the first occurrence of a value in a matrix - MATLAB Cody - MATLAB Central

Problem 1911. Find the index of the first occurrence of a value in a matrix

Difficulty:Rate

Given a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. For example

 input =
     0     0     0     0
    -1    -1     0     1
    -1     1     0    -1
     0     0     0     1

Find row number of first instance of -1 in each column

 output = [2 2 NaN 3]

Solution Stats

56.2% Correct | 43.8% Incorrect
Last Solution submitted on Feb 06, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers63

Suggested Problems

Problem Tags

Community Treasure Hunt

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

Start Hunting!