필터 지우기
필터 지우기

How to find single index values in a matrix?

조회 수: 4 (최근 30일)
Dalton Houghton-Schaffer
Dalton Houghton-Schaffer 2019년 9월 9일
답변: Walter Roberson 2019년 9월 9일
B1 = [2 4 6 8; 10 12 14 16; 18 20 22 24; 26 28 30 32]
idx_8=find(B1==8)
[row,column]=find(B1~=8)
RowColumn = [row:column]
Find the single index values for 26, 4, and 28?
How is a matrix indexed with single indexing values?
  댓글 수: 3
Dalton Houghton-Schaffer
Dalton Houghton-Schaffer 2019년 9월 9일
Is that the code to find single index values? And do I insert anything to the matrix [was_found]?
Walter Roberson
Walter Roberson 2019년 9월 9일
[was_found, idx] = ismember([26 4 28], B1);
will assign to two variables: was_found and idx. was_found will be true for each element of [26 4 28] that was located somewhere in B1, and will be false for any element that was not found in B1. idx will be 0 for any element that was not found, and otherwise will be the index of the "first" location of the value in B1. idx will be a "linear index"

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

채택된 답변

madhan ravi
madhan ravi 2019년 9월 9일
편집: madhan ravi 2019년 9월 9일
Linear_indices = find(ismember(B1,[26 4 28])); % you mean linear indices by saying single indices
B1(Linear_indices) % would give [26 4 28]
  댓글 수: 5
madhan ravi
madhan ravi 2019년 9월 9일
Ok so don't expect me to delete my answer though.
Bruno Luong
Bruno Luong 2019년 9월 9일
편집: Bruno Luong 2019년 9월 9일
No IMO you should keep it. The difference is interesting to highlight.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 9월 9일
[was_found, idx] = ismember([26 4 28], B1);
will assign to two variables: was_found and idx. was_found will be true for each element of [26 4 28] that was located somewhere in B1, and will be false for any element that was not found in B1. idx will be 0 for any element that was not found, and otherwise will be the index of the "first" location of the value in B1. idx will be a "linear index"

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by