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

Write a MATLAB program that uses the input function to prompt the user for an ar

ID: 3816629 • Letter: W

Question

Write a MATLAB program that uses the input function to prompt the user for an array of 4 values (warn the user to enter the numbers as an array) and store them in an array variable. Use a loop to fill a new array with the values from the first array in reverse order. Print the new array. Use a single line that refers to the input array with 4 indices to create a new array with the values from the first array in reverse order. Print the new array. We want to be able to create two sets of values from a loop value. For this example, we want to use MATLAB to create indices that would be useful in printing an array, of 16 values, 4 at a time. We will try these two ways. Write a for loop that runs from 1 to 4. Inside the loop determine an expression that will transform the loop variable into two variables, starting index and an ending index, whose values are as follows Print out the values of the starting and ending indices within the loop. b. Write a for loop that runs from 1 to 16 with increments of 4. Again, inside the loop determine an expression that will transform the loop variable into two variables, starting index and an ending index, whose values are as the same as they were in 2a. Print out the values of the starting and ending indices within the loop.

Explanation / Answer

1.a)

% Asking user to enter the array

A1=[];   

A = input('Enter values in array format');

% Checking wether entered value is numeric array or not

result = isnumeric(A);

%disp(result);

s=0;

if result == 1

% Checking wether entered value is numeric array or not

s = length(A);

% run the loop till the values enterd are 4

while s ~= 4

disp('Enter an array with 4 values only!!');

A = input('Enter values of the array');

s = length(A);

end

else

warning('Enter values in array format');   

end

% Reversing array using for loop

for i = 1:s

A1(i) = A(length(A)-i+1);

end

disp(A1);

1.b)

% Asking user to enter the array   

A = input('Enter values in array format');

% Checking wether entered value is numeric array or not

result = isnumeric(A);

%disp(result);

s=0;

if result == 1

% Checking wether entered value is numeric array or not

s = length(A);

% run the loop till the values enterd are 4

while s ~= 4

disp('Enter an array with 4 values only!!');

A = input('Enter values of the array');

s = length(A);

end

else

warning('Enter values in array format');   

end

% Reversing array in single line

A1=fliplr(A);

disp(A1);

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