How can I change rows that appeared more than once to missing rows
조회 수: 1 (최근 30일)
이전 댓글 표시
Please I need a help!!
I have the set of vectors below. In the second column, 5.0000 and 6.0000 appeared twice, and between 9.0000 and 12.0000, 10.0000 and 11.0000 are missing.
Please how can I change the rows with 5.0000 and 6.0000 to 10.0000 and 11.0000 that are missing and sort the second column in ascending with respect to their corresponding rows.
Please, I need a solution that is applicable to related problems.
2005.00 1.00000 0.000000 0.000000 0.000000
2005.00 2.00000 0.000000 0.000000 0.000000
2005.00 3.00000 0.000000 0.000000 0.000000
2005.00 4.00000 0.000000 0.000000 0.000000
2005.00 5.00000 0.000000 0.000000 0.000000
2005.00 6.00000 0.000000 0.000000 0.000000
2005.00 5.00000 56.0000 4464.00 1.25448
2005.00 6.00000 2937.00 4320.00 67.9861
2005.00 7.00000 2974.00 4464.00 66.6219
2005.00 8.00000 2097.00 4464.00 46.9758
2005.00 9.00000 797.000 4320.00 18.4491
2005.00 12.0000 191.000 4464.00 4.27867
This is my desired output
2005.00 1.00000 0.000000 0.000000 0.000000
2005.00 2.00000 0.000000 0.000000 0.000000
2005.00 3.00000 0.000000 0.000000 0.000000
2005.00 4.00000 0.000000 0.000000 0.000000
2005.00 5.00000 56.0000 4464.00 1.25448
2005.00 6.00000 2937.00 4320.00 67.9861
2005.00 7.00000 2974.00 4464.00 66.6219
2005.00 8.00000 2097.00 4464.00 46.9758
2005.00 9.00000 797.000 4320.00 18.4491
2005.00 10.00000 0.000000 0.000000 0.000000
2005.00 11.00000 0.000000 0.000000 0.000000
2005.00 12.0000 191.000 4464.00 4.27867
Thank you in advance.
댓글 수: 3
Dyuman Joshi
2022년 9월 23일
In this case, all empty rows are sent to the bottom, however in the earlier example there was still a row after them.
Please clarify this ambiguity and say what exactly do you want to do with the empty rows.
채택된 답변
dpb
2022년 9월 23일
편집: dpb
2022년 9월 23일
A=[
2005.00 1.00000 0.000000 0.000000 0.000000
2005.00 2.00000 0.000000 0.000000 0.000000
2005.00 3.00000 0.000000 0.000000 0.000000
2005.00 4.00000 0.000000 0.000000 0.000000
2005.00 5.00000 0.000000 0.000000 0.000000
2005.00 6.00000 0.000000 0.000000 0.000000
2005.00 5.00000 56.0000 4464.00 1.25448
2005.00 6.00000 2937.00 4320.00 67.9861
2005.00 7.00000 2974.00 4464.00 66.6219
2005.00 8.00000 2097.00 4464.00 46.9758
2005.00 9.00000 797.000 4320.00 18.4491
2005.00 12.0000 191.000 4464.00 4.27867];
% engine
d=setdiff([1:size(A,1)].',A(:,2));
n=histc(A(:,2),unique(A(:,2)));
A(n>1,2)=d;
A=sortrows(A,[1:2]);
format bank % to prettify output only
disp(A)
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!