Assignment Help >> MATLAB Programming
Assignment -
1. Write a Matlab script to generate an array of 100 random samples between -5 and 5. The script should then copy the samples one by one to a new array, and check if they are within a limit range set between variables min and max, set at -2 and 2, respectively. If a sample is outside the range, it should be set to the limit value. Using the script, plot both arrays on the same figure.
2. Write a Matlab script to generate the plots of y = 5x^{2}, where x is within [0, 10].
- The step size of x in the first plot is 0.2.
- The step size of x in the second plot is 0.5.
- The step size of x in the third plot is 1.
- The step size of x in the fourth plot is 2.
In the script, use the subplot command to display four plots on one figure.
- Plot 1 should choose the red color.
- Plot 2 should choose the blue color.
- Plot 3 should choose the green color.
- Plot 4 should choose the black color.
- The point format in each plot should choose '+';.
- The connection between dots should be dashed '--'.
3. Write a Matlab function that will accept an array of numbers. The function should sort the values from lowest to highest using two loops. Do not use the sort() or similar pre-made Matlab functions.
(Hint: one way to do this is a bubble sort algorithm. Use a "for" loop that repeats n-1 times, where n is the number of elements in the array. Within that loop, use another "for" loop that indexes through each element of the array (from 1 to n-1), compares it with the next highest element, and switches them if the first number is larger than the second.)