Adding Value in the array with proper indexing
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
Hi, here i have an array with random values, i have sort them and divide them in maximum and minimum values, after sorting the array the index of values is changes, if i want to add the minvalues in the orignal unsorted array with proper indexing. how should i do it?  
ME=4;
    E=rand(1,ME)
    ES=sort(E,'descend')
    Ls=length(ES);
    Hl=(Ls/2);
    maxval=ES(1:Hl);
    minval=ES(Hl+1:end);
댓글 수: 5
  Rik
      
      
 2019년 3월 27일
				That is just the output of your current code, not the output of want as the end result. What vector do you want to have?
채택된 답변
  Andrei Bobrov
      
      
 2019년 3월 28일
        ME=4;
E=rand(1,ME);
[ES,ii]=sort(E,'descend');
Ls=length(ES);
Hl=(Ls/2);
maxval=ES(1:Hl);
mxii = ii(1:Hl);
minval=ES(Hl+1:end);
mnii = ii(Hl+1:end);
Enew = E;
Enew(mnii) = Enew(mnii) + minval
추가 답변 (1개)
  Andrei Bobrov
      
      
 2019년 3월 27일
        ME=4;
E=rand(1,ME);
[ES,ii]=sort(E,'descend');
Ls=length(ES);
Hl=(Ls/2);
maxval=ES(1:Hl);
mxii = ii(1:Hl);
minval=ES(Hl+1:end);
mnii = ii(Hl+1:end);
Enow = sortrows([maxval(:),mxii(:);minval(:),mnii(:)],2);
Enow = Enow(:,1);
참고 항목
카테고리
				Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



