How can I change rows that appeared more than once to missing rows
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Dyuman Joshi
el 23 de Sept. de 2022
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.
Respuesta aceptada
dpb
el 23 de Sept. de 2022
Editada: dpb
el 23 de Sept. de 2022
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!