File Exchange

image thumbnail

Array sorting

version 1.1 (1.15 KB) by

Program for Sorting of Array in Matlab



View License

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
statements Etc...

Here is the surprise, Matlab has an inbuilt function called 'sort' for sorting any array.

Comments and Ratings (2)

satendra kumar

@jan: Thanks for your valuable comment.
I have updated this file to a user oriented function.
Further Comments and queries are dearly invited.

Jan Simon

Jan Simon (view profile)

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.
Upon calling this function in matlab command window it will ask for the user input data.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today