Sorting an array without sort() command
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need to sort an array without the sort() command and the array is user inputed.
Like given an array [1, 3, 2] needs to be [1, 2, 3] or [1, 3, 2; 4, 5, 6; 9, 8, 7] needs to be [1, 2, 3; 4, 5, 6; 7, 8, 9].
I need to compare the number with all the other nnumbers in the array and then If selected number is greater than any of the next numbers, swap their location.
2 comentarios
Soumya
el 27 de Ag. de 2024
I need to sort an array without the Sort() command and the array is user input.
Like [12, 2 , 7, 9, 10 ] need to be [2, 7, 9, 10, 12].
I need to compare the number with all the other nnumbers in the array and then If selected number is smaller than any of the next numbers, swap their location but I want to use Stateflow for this.
Steven Lord
el 27 de Ag. de 2024
I need to sort an array without the Sort() command and the array is user input.
Okay.
Like [12, 2 , 7, 9, 10 ] need to be [2, 7, 9, 10, 12].
I need to compare the number with all the other nnumbers in the array and then If selected number is smaller than any of the next numbers, swap their location but I want to use Stateflow for this.
Why are you using Stateflow for this? Is this part of a homework assignment or something? Or are you trying to generate code for a hardware target or something similar? If the latter, consider the Sort block from DSP System Toolbox.
If this is homework, show us what you've done so far to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
Respuestas (2)
KSSV
el 23 de Oct. de 2020
and many more..you can do a search before asking a simple question which is discussed lot many times.
3 comentarios
Ameer Hamza
el 23 de Oct. de 2020
Editada: Ameer Hamza
el 23 de Oct. de 2020
What you described is called selection sort. This FEX package have code for all commonly know sorting algorithms, including the selection sort: https://www.mathworks.com/matlabcentral/fileexchange/45125-sorting-methods
2 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!