I need to make a loop that will show and count elements that are smaller that 10 in matrix A

A=[95 46 92 41 14 2 85; 23 2 74 89 20 75 53; 61 82 18 6 20 45 20; 89 62 94 81 27 47 84; 76 79 92 1 20 42 2]

Answers (1)

Why do you need a loop? MATLAB's indexing tools are much more powerful than low-level loops:
>> A = [95,46,92,41,14,2,85; 23,2,74,89,20,75,53; 61,82,18,6,20,45,20; 89,62,94,81,27,47,84; 76,79,92,1,20,42,2];
>> X = A<10; % indices of values less than ten
>> nnz(X(:)) % count those values
ans = 5
>> A(X) % show those values
ans =
2
6
1
2
2
>>

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

on 2 Nov 2015

Edited:

on 2 Nov 2015

Community Treasure Hunt

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

Start Hunting!