Adding Value in the array with proper indexing
Show older comments
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 Comments
madhan ravi
on 27 Mar 2019
Edited: madhan ravi
on 27 Mar 2019
Show an example of your desired output. Also have no idea why you deleted the previous question without responding to the comments.
Maheen Fazal
on 27 Mar 2019
Maheen Fazal
on 27 Mar 2019
Rik
on 27 Mar 2019
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?
Maheen Fazal
on 27 Mar 2019
Accepted Answer
More Answers (1)
Andrei Bobrov
on 27 Mar 2019
0 votes
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);
1 Comment
Maheen Fazal
on 28 Mar 2019
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!