Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB program that prompts the user for a starting value and an ending

ID: 3816640 • Letter: W

Question

Write a MATLAB program that prompts the user for a starting value and an ending value. They each can be positive or negative. Prompt the user for a number of elements to use in an array. Create an array the size the user has indicated with values evenly spaced between the starting and ending values. This is very easy to do using the lines pace function. Print the array, printing five values per line, unless the last line requires fewer to finish printing the array. A simple if check Inside the array may be helpful. Test this with many values. A decent start test Is going from 1 to 12 for a 23-element array.

Explanation / Answer

Program:

min = input('Enter minimum limit : ');
max = input('Enter maximum limit : ');
n= input('Enter number of elements : ');
arr=zeros(1,n);
for i=1:n
arr(i) = uint8(min+(max-min).*rand());
end
arr

Result:

>> limits
Enter minimum limit : 5
Enter maximum limit : 8
Enter number of elements : 20

arr =

5 7 7 7 8 8 7 7 8 7 5 5 8 6 8 6 7 7 5 7

>> limits
Enter minimum limit : 1
Enter maximum limit : 12
Enter number of elements : 23

arr =

Columns 1 through 22

5 2 6 3 2 3 3 3 1 8 4 7 9 6 7 6 2 6 10 11 4 3

Column 23

7

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote