필터 지우기
필터 지우기

Changing Indexing Order in matrix raws

조회 수: 4 (최근 30일)
Kostiantyn Cherkas
Kostiantyn Cherkas 2019년 5월 1일
댓글: ahmad tourei 2020년 5월 5일
Good day, everyone! I have the following array(1) = [0 0 0 0 0 0 0 0 0 1 2 3 4 5] (14 elements in total, for example) and I can derrive respective indexes of the elements in it. The other array(2) = [12 11 14 5 1] contains a set of indexes for non-zero elements in array(1) (mapping one-to-one - so 1 should have index 12, 2 - index 11, etc.). How can I sort array(1) with respect to indexes in array(2) with no use of loop structure? (I solved it with loop) .

채택된 답변

KSSV
KSSV 2019년 5월 1일
a1 = [0 0 0 0 0 0 0 0 0 1 2 3 4 5] ;
a2 = [12 11 14 5 1] ;
a3 = zeros(size(a1)) ;
a3(a2) = a1(a1~=0)
  댓글 수: 1
ahmad tourei
ahmad tourei 2020년 5월 5일
Thanks a lot. after searching for 2 deays, i found my answer for labeling the rows and colomns of matrices by reading your suggest.

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

추가 답변 (2개)

madhan ravi
madhan ravi 2019년 5월 1일
array1(array1~=0)=array2

Jos (10584)
Jos (10584) 2019년 5월 1일
Your question is a little confusing, but here is my take on it:
A1 = [0 0 0 0 0 0 0 0 0 1 2 3 4 5]
A2 = [12 11 14 5 1]
out([numel(A1) A2]) = [0 A1(A1~=0)]
% 5 0 0 0 4 0 0 0 0 0 2 1 0 3

카테고리

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