Effacer les filtres
Effacer les filtres

Selection of 3 large value from a matrix

1 vue (au cours des 30 derniers jours)
Tinkul
Tinkul le 7 Avr 2014
Commenté : Tinkul le 7 Avr 2014
How can i select 3 largest value from a matrix and remaining make zero without changing the dimension,For eg A=[1 3 5 8 31 7 4 18] The output should be A=[0 0 0 8 31 0 0 18] Please help

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 7 Avr 2014
Modifié(e) : Azzi Abdelmalek le 7 Avr 2014
A=[1 3 5 8 31 7 4 18]
[ii,jj]=sort(A,'descend');
A(jj(4:end))=0
Or
A=[1 3 5 8 31 7 4 18]
[ii,jj]=sort(A,'descend');
B=zeros(size(A))
B(jj(1:3))=A(jj(1:3))
  1 commentaire
Tinkul
Tinkul le 7 Avr 2014
Thank you...Awsome...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by