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 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!