% Script to add the elements of a vector clear x = [1 5 7 -6 9 3 -1] %x = rand(100,1); total = 0; % set total to 0 for i = 1:length(x) total = total + x(i); % add next element of x to total end total sum(x) % compare with built-in sum function