This Example will help you in getting the basics of programmatic as well
As the various commands used in matlab, Use of Loops, Use of Conditional
Here is the surprise, Matlab has an inbuilt function called 'sort' for sorting any array.
@jan: Thanks for your valuable comment.
I have updated this file to a user oriented function.
Further Comments and queries are dearly invited.
This is not a good programming example. The "clear all" is useless here and removing all loaded fucntions from the memory is a waste of time and energy. Even the less brute "clear variables" cannot be recommended here: Better check you code, if all uses variables are defined. If they are, the unconditional clearing is inefficient.
Does "nos" mean "numbers"?
Do you see, that "a" is underlined by MLint? This means, that MATLAB found out, that this command is inefficient, because you do not pre-allocate "a". Just hold the mouse over the underlined symbol to learn more about MLint.
The sorting algorithm is inefficient, but the implementation is not clean: There is no reason to run the FOR loop over i until 5.
It would be much nicer, if the data length is not fixed to 5, but can be changed by the user through an input. I'd prefer to convert this to a function, instead of a script.
I have updated the Script file to a Function called 'Array_sort'. Which is more user input oriented, with a variable size of array.