Gistlib Logo

gistlib

write a function sumeveryother( v ) that takes in a vector and returns the sum of every other element, starting with the first element and make it without using loops in matlab

main.m
function res = sumeveryother(v)
    res = sum(v(1:2:end));
end
63 chars
4 lines

similar matlab code snippets

create an array of 100 different car models and sort them by color in matlab
display dlarray data format in matlab
how to replace each element of a array with the row cell of another array in matlab
convert field of a struct into an array in matlab
how to calculate the transpose of a matrix in matlab
convert a 5 by 10 array into a 2 by 25 cell array in matlab
minimam algorithm in matlab
perfect number in matlab
get the last element of an array in matlab
how to calculate the sum of a matrix in matlab

related categories

`matlab
array
function`

gistlibby LogSnag