Finding the first value in a matrix

Hello,
In my matrix c, how do I find the first time the value 700 appears searching one row at a time before moving onto the next?
Thank you.

Answers (2)

Jan
Jan on 26 Apr 2021
Edited: Jan on 26 Apr 2021
c = [0, 0, 700; 1, 2, 3; 4, 700, 1];
d = c.';
[col, row] = find(d == 700, 1)
i2 = 3
i1 = 1
Here the column index is replied at first, because the input was transposed.
I am not certain what you want.
Try this —
c = randi([650 750], 25);
[cr,cc] = find(c==700)
cr = 12×1
18 3 13 3 19 22 24 6 12 19
cc = 12×1
2 4 7 9 12 14 17 19 21 21
[RowMin,Idx] = min(cr)
RowMin = 3
Idx = 2
First700 = [RowMin, cc(Idx)]
First700 = 1×2
3 4
.

Categories

Tags

Asked:

on 26 Apr 2021

Answered:

on 26 Apr 2021

Community Treasure Hunt

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

Start Hunting!