Create a function in MATLAB that sorts the values of X in in

Create a function in MATLAB that sorts the values of X in increasing order using:

arithmetic operations (+, -, *,/)

• logical operations (<,<=,==,>=, >, &&, ||, ~,~=)

• conditional statements (if… elseif… else… end)

• loops (while loop, for loop)

• I/O (display, input())

• Scalars, vectors, and matrices

Solution

Program to sort n random numbers in ascending order

x = 1:n;

a = randn(size(x))

for (j = 1: n)

for (i = 1: n)

if a(i) > a(i+1)

t = a(i);

a(i) = a(i+1)

;a(i+1) = t

end;

end;

end;

a

Create a function in MATLAB that sorts the values of X in increasing order using: arithmetic operations (+, -, *,/) • logical operations (<,<=,==,>=, &

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site