How to sort a vector based on the absolute difference of the sorted vector
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Baththama Alhassan
el 14 de Dic. de 2021
Comentada: Baththama Alhassan
el 20 de Dic. de 2021
Example: a= [2,3,6,12,7,18,25,0,28,5]
b= [0,2,3,5,6,7,12,18,25,28]
absolutediffofb=[2,1,2,1,1,5,6,7,3]
arrangeb=[(2,3)(5,6)(6,7)(0,2)(3,5)(25,28)(7,12)(12,18)(18,25)]
2 comentarios
Awais Saeed
el 14 de Dic. de 2021
It is not clear what you are trying to do? How do you read 'arrangeb'? Show us what have you tried and what issues are you facing.
Respuesta aceptada
David Goodmanson
el 14 de Dic. de 2021
Hi Awais,
a= [2,3,6,12,7,18,25,0,28,5]
b = sort(a)' % column vector
c = [b(1:end-1) b(2:end)];
d = [diff(c,[],2) c];
e = sortrows(d)
e =
1 2 3
1 5 6
1 6 7
2 0 2
2 3 5
3 25 28
5 7 12
6 12 18
7 18 25
The ordered pairs are in columns 2 and 3. Some format like this is necessary since
[(2,3)(5,6)(6,7)(0,2)(3,5)(25,28)(7,12)(12,18)(18,25)]
is not part of Matlab syntax.
3 comentarios
Image Analyst
el 15 de Dic. de 2021
Where is "arrangeb"? It looks like you might be missing this:
arrangeb = e(:, 2:3);
Más respuestas (0)
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices 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!