How can I remove a word from an array?

2 visualizaciones (últimos 30 días)
Marcela Ruiz de Chávez
Marcela Ruiz de Chávez el 4 de Nov. de 2013
Comentada: Marcela Ruiz de Chávez el 4 de Nov. de 2013
This is what I have:
xA=[0 4 2 1]; wA=struct('name',{'person1' 'person2' 'person3' 'person4'},'num',num2cell(xA)); peopleA={wA.name}; numA=[wA.num]; [idxA,idxA]=max(numA); primeroA=peopleA{idxA} numAA=numA(numA~=max(numA)); [idxxA,idxxA]=max(numAA); segundoA=peopleA{idxxA}
I want to remove the maximum of the word, that is, the word contained in primeroA, in order to be able to calculate the second maximum without the words being rearrenged or altered.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 4 de Nov. de 2013
xA=[0 4 2 1];
name={'person1' 'person2' 'person3' 'person4'};
[a,b] = unique(xA);
out = name(b(end-1));

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Nov. de 2013
Editada: Azzi Abdelmalek el 4 de Nov. de 2013
xA=[0 4 2 1];
wA=struct('name',{'person1' 'person2' 'person3' 'person4'},'num',num2cell(xA));
peopleA={wA.name};
numA=[wA.num];
[idxA,idxA]=sort(numA,'descend');
primeroA=peopleA{idxA(1)}
segundoA=peopleA{idxA(2)}
terceroA=peopleA{idxA(3)}
  1 comentario
Marcela Ruiz de Chávez
Marcela Ruiz de Chávez el 4 de Nov. de 2013
Thank you soo much!! You are a genius! I'm sorry..I accepted the wrong answer and I don't know how to unaccept it. But thank you very much!

Iniciar sesión para comentar.

Categorías

Más información sobre Word games en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by