# Find elements in a matrix

1 visualizzazione (ultimi 30 giorni)
Hanna Sundling il 14 Nov 2019
Commentato: Guillaume il 14 Nov 2019
The task is to find how many of the elements in A is numbers between 30 and 65, how do I find that? My code looks like this:
##### 1 CommentoMostra NessunoNascondi Nessuno
Daniel M il 14 Nov 2019

Accedi per commentare.

### Risposte (2)

M il 14 Nov 2019
Modificato: M il 14 Nov 2019
You can get the indices with:
idx = A >= 30 & A <= 65
To know the number of values corresponding to the condition:
numel(find(idx))
##### 1 CommentoMostra NessunoNascondi Nessuno
Guillaume il 14 Nov 2019
nnz(idx)
is simpler and faster than numel(find...)

Accedi per commentare.

Ruger28 il 14 Nov 2019
This really isnt code, or even an attempt....but
A = randi([10,100],8,20);
B = A(A>=30 & A <= 65); % logically index A using your limits
using FIND
A = randi([10,100],8,20);
C = find(A>=30 & A<=65); % get index of values in your window
D = A(C); % get values in A
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Logical in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by