write a function sumeveryother( v ) that takes in a vector and returns the sum of every other element, starting with the first element. if the vector is empty, your function should return zero. in matlab

main.m
function result = sumeveryother(v)
    if isempty(v)
        result = 0;
    else
        result = sum(v(1:2:end));
    end
end
128 chars
8 lines

related categories

gistlibby LogSnag