Cody

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

Solution 1286055

Submitted on 13 Oct 2017 by Noriko Hounoki
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = [0 1;-1 0]; y_correct = [2 NaN]; assert(isequaln(findfirst(x),y_correct))

cn = 2 y = NaN NaN ckc = [] pos = 2 y = 2 NaN pos = 0×1 empty double column vector

2   Pass
x = [0 0 -1;2 -1 0]; y_correct = [NaN 2 1]; assert(isequaln(findfirst(x),y_correct))

cn = 3 y = NaN NaN NaN ckc = [] pos = 0×1 empty double column vector pos = 2 y = NaN 2 NaN pos = 1 y = NaN 2 1

3   Pass
x = [0 1 0 -1;-1 -1 0 1;-1 1 0 -1;0 0 0 1]; y_correct = [2 2 NaN 1]; assert(isequaln(findfirst(x),y_correct))

cn = 4 y = NaN NaN NaN NaN ckc = [] pos = 2 y = 2 NaN NaN NaN pos = 2 y = 2 2 NaN NaN pos = 0×1 empty double column vector pos = 1 y = 2 2 NaN 1

Community Treasure Hunt

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

Start Hunting!