MATLAB: If an array contain 6 data elements then make the addition of all the data of that array (with built in function i.e using sum)

array

what I should modify the following code and can explain how we can define with built in function and without built in function.
s=0;
a=[1 3 5 7 8 6]
for(i=1:1:4)
s=s+a(i);
end
disp('sum=')
disp(s)

Best Answer

If an array has 6 elements, do not just add the first 4 of them.
For information about the built-in command sum, give the command
doc sum