MATLAB: Finding positions and adding them together

newlearner

% Author: Sean Walsh % Create a vector of 53 random #s and analyze them. disp('Your 53 random numbers are') r = rand([53,1]) disp('Their sum adds up to') sum(r) disp('When multiplied together, their product is') prod(r) disp('The mean of the vector is') mean(r) disp('The median of the vector is') median(r) disp('The stand deviation ofthe vector is') std(r) disp('The length of the vector is') length(r) disp('The size of the vector is') size(r) disp('The minimum value of the vector is') min(r) disp('The maximum value of the vector is') max(r)
Question: How can I find the value in positions 2, 15,22, and 35 and add them together?

Best Answer

sum(r([2 15 22 35]))