Logical Indexing with Condition Involving Functions

조회 수: 5 (최근 30일)
Andrew Anderson
Andrew Anderson 2021년 5월 5일
편집: Andrew Anderson 2021년 5월 5일
Suppose I created a function F, and I want to find all elements a in an array A such that F(a) is some value of the function. Is there any way to do this with logical indexing (or some other method)? I tried to use idx = (F(A) == 1), but it has been giving me error messages about different numbers of elements. Thanks in advance!
  댓글 수: 2
Stephen23
Stephen23 2021년 5월 5일
"but it has been giving me error messages about different numbers of elements"
Please show the complete error message. This means all of the red text.
Andrew Anderson
Andrew Anderson 2021년 5월 5일
"Unable to perform assignment because the left and right sides have a different number of elements."

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

답변 (1개)

VBBV
VBBV 2021년 5월 5일
%if true
idx = find(A(a) == 1)
Use it with find function for element indices
  댓글 수: 2
Stephen23
Stephen23 2021년 5월 5일
Note that the question specifically requests logical indices, not linear indices.
Andrew Anderson
Andrew Anderson 2021년 5월 5일
This may suffice, as I do not have to use logical indexing (I will edit the question accordingly). I will try it out some time.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by