Find elements in a matrix

조회 수: 1 (최근 30일)
Hanna Sundling
Hanna Sundling 2019년 11월 14일
댓글: Guillaume 2019년 11월 14일
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:
Skärmavbild 2019-11-14 kl. 15.23.15.png

답변 (2개)

M
M 2019년 11월 14일
편집: M 2019년 11월 14일
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
Guillaume
Guillaume 2019년 11월 14일
nnz(idx)
is simpler and faster than numel(find...)

댓글을 달려면 로그인하십시오.


Ruger28
Ruger28 2019년 11월 14일
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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by