Sorting matrix while removing zero values and keeping track of index at the same time.

조회 수: 7 (최근 30일)
This is after sorting but with zero values as well.
[a,ind] = sort(totalAmplitude);
bb = [a;ind]';
I want to eliminate the zero values along with its index value as well.
I tried this but this is messing up my original index as well. The index very much needed for me.
[total_amp_temp,index] = sort(nonzeros(totalAmplitude));
ccd = [total_amp_temp index];
I have attached MATFILE as well.

채택된 답변

CalebJones
CalebJones 2020년 2월 11일
[a,ind] = sort(totalAmplitude);
bb = [a;ind]';
check = find(bb == 0);
bb(check,:) = [];

추가 답변 (1개)

Bhaskar R
Bhaskar R 2020년 2월 11일
totalAmplitude(ind == 0)=[];
  댓글 수: 1
CalebJones
CalebJones 2020년 2월 11일
I need to keep a track of original index as well.
The index is the most important thing for me, since I'll be using the index for comparision later.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by