Add the first k elements in an array with Matlab


/ Published in: MatLab
Save to your folder(s)

A simple function in Matlat to add the first k elements in an array


Copy this code and paste it in your HTML
  1. function sum = sumk (array , k)
  2. sum = 0;
  3. for i = 1:k
  4. sum = sum + array(i);
  5. end
  6.  
  7. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.