How can I remove a word from an array?
1 回表示 (過去 30 日間)
古いコメントを表示
Marcela Ruiz de Chávez
2013 年 11 月 4 日
コメント済み: Marcela Ruiz de Chávez
2013 年 11 月 4 日
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.
0 件のコメント
採用された回答
Andrei Bobrov
2013 年 11 月 4 日
xA=[0 4 2 1];
name={'person1' 'person2' 'person3' 'person4'};
[a,b] = unique(xA);
out = name(b(end-1));
0 件のコメント
その他の回答 (1 件)
Azzi Abdelmalek
2013 年 11 月 4 日
編集済み: Azzi Abdelmalek
2013 年 11 月 4 日
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)}
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!