__Answers:__

As per the hint, find the length of vector 'x' and store it in some variable, here in 'y', for ease. Then write the for loop as follows to get the desired output:

x = [1 2 6 4 2]

y=length(x)

s=0;for i=1:y

s = s + x(i)

disp(s)

end

As per the hint, find the length of vector 'x' and store it in some variable, here in 'y', for ease. Then write the for loop as follows to get the desired output:

x = [1 2 6 4 2]

y=length(x)

s=0;for i=1:y

s = s + x(i)

disp(s)

end

Login to add comment