How to campare index number of a matrix with other
조회 수: 1 (최근 30일)
이전 댓글 표시
I have two array. A=[ 9 8 5 4 4 10] and B=[1 1 1 3 3 3 2 2 1 1]. Now, I want to campare A and B. The index number of each element in matrix B is same in matrix A. I want to represent the matrix A by the value of matrix B as its index number is same with. Now I want to represent matrix A as like B i.e. A will be A=[1 2 3 3 3 1]. How will write it code.
댓글 수: 0
채택된 답변
Raj
2019년 4월 15일
for i=1:numel(A)
A(i)=B(A(i));
end
댓글 수: 6
Stephen23
2019년 4월 15일
편집: Stephen23
2019년 4월 15일
"...the 'for loop' code gives a better understanding of what is happening in the background.
I disagree: MATLAB is a high-level language and array indexing is one of its most powerful features. Learning how to use array indexing is not more complex than a loop: Riks solution is simpler than this answer and more efficient.
Array indexing is required for any user who wants to learn how to use MATLAB effectively.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!