MATLAB: Finding a specific rows

identification

I have this Matrix:
m = [0 0 0 0 0 0 0 0
0 3.410 0 0 0 0 0 0
10.83 11.87 7.240 3.470 1.610 1.610 0 0
20.99 18.23 17.72 6.010 3.790 3.790 1.100 0
25.26 20.40 22.70 7.590 6.990 6.990 1.550 0
22.86 19.13 24.48 8.280 9.240 9.240 2.180 0
14.92 15.73 23.19 8.280 11.61 11.61 2.690 0
10.83 11.87 22.18 8.280 12.79 12.79 3.010 0
9.050 10.69 22.70 8.490 14.91 14.91 3.500 0
9.840 11.19 23.75 8.490 16.02 16.02 3.790 0
9.840 11.54 24.48 8.840 16.43 16.43 4.100 0
8.070 10.20 25.18 9.180 17.73 17.73 4.750 0
5.230 8.350 24.48 9.180 19.28 19.28 5.800 0
3.680 6.630 25.18 8.840 22.49 22.49 6.980 2.190
0 3.190 22.70 7.840 28.06 28.06 8.280 3.320
0 0 13.03 6.010 34.68 34.68 10.88 5
0 0 0 3.470 32.87 32.87 13.86 5.300
0 0 0 0 15.14 15.14 12.27 0
0 0 0 0 1.240 1.240 1.450 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
40.53 25 0 0 0 0 0 0]
% * Edited by Adam Danz to allow for copy-pasting into command window
I want to find the first row where all the columns have a value below 10. How to do this? I have made an if statement, but this seems to specific and I was wondering if there would be another way.

Best Answer

This does not require a for-loop. In fact, the last line is the solution. The first few lines just creates an example matrix where rows 3 and 13 are all below 10.
% Create a 15x7 matrix of random integers 1:20
m = randi(20,15,7);
% Rows 3 and 13 are all below 10 (maybe others, too)
m([3,13],:) = m([3,13],:)-11;
%find the first row where all the columns have a value below 10.
rowNumber = find(all(m < 10,2),1);
% find the first row AFTER ROW N where all columns are < 10
N = 3; %start at row N
rowNumber = find(all(m(N:end,:) < 10,2),1)+N-1;
Related Question