Selection of 3 large value from a matrix

조회 수: 1 (최근 30일)
Tinkul
Tinkul 2014년 4월 7일
댓글: Tinkul 2014년 4월 7일
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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 7일
편집: Azzi Abdelmalek 2014년 4월 7일
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))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by