I need to find the sum and average of values in a vector without using the mean or sum function, using a FOR loop statement. Let's say my vector is x =[1:1:20]. So far, I have
theSum = 0;
for k =1:length(x);
theSum = theSum + x(k);
fprintf('The total value of x is %.1f, and the average value of x is %.3f\n\n',...
I only want to display the final iteration. I'm guessing I need to use the break command, but I don't know how to or where in my statement.