Adding Value in the array with proper indexing

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 comentarios

madhan ravi
madhan ravi el 27 de Mzo. de 2019
Editada: madhan ravi el 27 de Mzo. de 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
Maheen Fazal el 27 de Mzo. de 2019
i just want to give the clear idea what i want to ask ,thats why deleted the previous one
Maheen Fazal
Maheen Fazal el 27 de Mzo. de 2019
Output
E =
0.0305 0.7441 0.5000 0.4799
ES =
0.7441 0.5000 0.4799 0.0305
>> maxval
maxval =
0.7441 0.5000
>> minval
minval =
0.4799 0.0305
here the minval from the unsorted array are 1st and 3rd, if i again want to add these values in the previous array how shall i add them ?
Rik
Rik el 27 de Mzo. de 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
Maheen Fazal el 27 de Mzo. de 2019
I want to add
E(4)+minval(1) and
E(1)+minval(2)

Iniciar sesión para comentar.

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 28 de Mzo. de 2019

0 votos

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

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 27 de Mzo. de 2019

0 votos

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 comentario

Maheen Fazal
Maheen Fazal el 28 de Mzo. de 2019
Sir, i want to add minval in the E array with same index values
e.g. if in the minval i have index 3,1 so i want to add them in the E array in their corresponding positions

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 27 de Mzo. de 2019

Comentada:

el 29 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by