I am learning how to use MATLAB and have been told there is a way to create a loop that will also output the sum and the average. What I have done so far is to create an array of a random sort of numbers and printed out each element as shown below:
% Variables
x = [1.8 3.6 5.4 7.2];fprintf('x =');disp(x);% For Loop
for k = 1:length(x); fprintf('Element %0.0f is: %0.1f \n', k, x(k));end
What I need to figure out next is how to use the 'for' loop to also print out the sum and average.
Best Answer