MATLAB Question Write a program that utilizes a while loop t
(MATLAB Question) Write a program that utilizes a while loop to calculate the sum of the numbers in a vector that will be specified by the user on the keyboard. The user will be asked to enter the vector and the loop will run through to determine the sum of the numbers. Test your code with vector -550:3:100
Solution
% matlab code to input vector and determine the sum of numbers in vector
vector = input(\'Input your vector: \');
i = 1;
sum = 0;
while true
sum = sum + vector(i);
i = i + 1;
if i > length(vector)
break
end
end
fprintf(\"Sum of the numbers: %f\ \",sum);
%{
output:
Input your vector: [-550:3:100]
Sum of the numbers: -49042.000000
Input your vector: [1 2 3 4 5]
Sum of the numbers: 15.000000
%}
