You are on page 1of 2

Code For Sorting A Vector/Array In Descending

Order
Allen Banez, Karl Cabidog, and Ruther Casison
University of Santo Tomas, Espaa Blvd., Manila 1015 Philippines
vmada@ust.edu.ph, jasilo@ust.edu.ph, ruthergene@gmail.com
Abstractcreating a function that ask for an input
vector/array, the code shall sort the vector/array in descending
order, the output shall show the sorted vector/array.
Keywordssorting;descending;array; vector;

I.

INTRODUCTION

This template, modified in MS Word 2007 and saved as a


Word 97-2003 Document for the PC, provides authors with
most of the formatting specifications needed for preparing
electronic versions of their papers. All standard paper
components have been specified for three reasons: (1) ease of
use when formatting individual papers, (2) automatic
compliance to electronic requirements that facilitate the
concurrent or later production of electronic products, and (3)
conformity of style throughout conference proceedings.
Margins, column widths, line spacing, and type styles are
built-in; examples of the type styles are provided throughout
this document and are identified in italic type, within
parentheses, following the example. Some components, such
as multi-leveled equations, graphics, and tables are not
prescribed, although the various table text styles are provided.
The formatter will need to create these components,
incorporating the applicable criteria that follow.
II. CODE DESCRIPTION
A. Code
Function b = downsort(a)
x2= 1:length(a);
for k=1:length(a);
[C, I]=min(a);
a(I)=[];
x2(k)=C;
end
x2new = fliplr(x2);
b =x2new;
disp(b);
end
B. Code theory
The function will ask the user to input a vector/array in
variable a, the code then shall calculate the maximum length
of the vector for looping purposes, under a for loop from 1 to
the length of the vector the code shall reiterate each element

of the array/vector from lowest to highest and create a new


array x2new in which the elements of array a are in ascending
order. After iteration process the code shall flip the array
x2new using flip function making ascending order into
descending order. Lastly the code then shall put the
descending ordered array into the output variable b and
display the output variable b.
III. RESULTS
Calling downsort function downsort (a), inputting a test
vector of a = [2 5 3 1 9 7 4], the function resulted to an output
of b = [9
7
5
4
3
2
1]. Resulting to a sorted
array in descending order.

IV. CONCLUSION
A user defined function of downsort(a) asking the user to
input a vector/array in which the code sorted in descending
order are coded in the function. The output of the function
then displayed the inputted vector in descending order. With
this result the task of creating a function that will sort in
descending order a vector of any length is attained, concluding
the task to be successful.

References
[1]

[2]
[3]

[4]
[5]
[6]

[7]

G. Eason, B. Noble, and I.N. Sneddon, On certain integrals of


Lipschitz-Hankel type involving products of Bessel functions, Phil.
Trans. Roy. Soc. London, vol. A247, pp. 529-551, April 1955.
(references)
J. Clerk Maxwell, A Treatise on Electricity and Magnetism, 3rd ed., vol.
2. Oxford: Clarendon, 1892, pp.68-73.
I.S. Jacobs and C.P. Bean, Fine particles, thin films and exchange
anisotropy, in Magnetism, vol. III, G.T. Rado and H. Suhl, Eds. New
York: Academic, 1963, pp. 271-350.
K. Elissa, Title of paper if known, unpublished.
R. Nicole, Title of paper with only first word capitalized, J. Name
Stand. Abbrev., in press.
Y. Yorozu, M. Hirano, K. Oka, and Y. Tagawa, Electron spectroscopy
studies on magneto-optical media and plastic substrate interface, IEEE
Transl. J. Magn. Japan, vol. 2, pp. 740-741, August 1987 [Digests 9th
Annual Conf. Magnetics Japan, p. 301, 1982].
M. Young, The Technical Writers Handbook. Mill Valley, CA:
University Science, 1989.

You might also like