Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 3 (15 points): Recall problem 3 in homework 6. 1 Write a function mydsort that receives one vector as input argument, sorts the vector
Problem 3 (15 points): Recall problem 3 in homework 6. 1 Write a function mydsort that receives one vector as input argument, sorts the vector in descending order, and return the sorted vector as output argument, using for-loop. For example, if the input vector vec-17 9 8 9 3 -8-5 10 10], then the output vector outve 10 10 9 9 7 3 1-5-8-8]. This function should work generally for any kind of input vectors (such as vectors that contain random numbers) 3.2 Test your function in the MATLAB Command window by generating a 1-by-10 row vector that contains random integer numbers in the inclusive range [-10 10] For example, vec-randi-10 10,, 10) vec = 4 -10 -5 -10 -8 7 4 -4 9 -10 ovecmydsort (vec) ovec = 9 7 4 4 -4 -5 -8 10 10 -10 Hints: To finish this function, nested for-loop and algorithm of exchanging two variables are needed. There is one built-in MATLAB function sort that can realize the same function. Try it sortivec, 'descend)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started