MATLAB Answers

# How do I change the increment in a loop

2,282 views (last 30 days)
MATTHEW FOX on 9 May 2017
Commented: Anga Vijay on 27 Jan 2021
I have been asked to write a function that calculates the sum of the series;
2^(5*i-1)
where i = 1,3,5... I currently have
function s = summation(N)
% Syntax
% s = summation (N)
% Input
% N = Number of terms in series
%Output
% sum of series
%Initilising loop to be zero
s = 0;
for i = 1:N
% loop adds previous value of s to the next one
s = s + 2^(5*i-1);
end
% increasing increment i by 2 from 1 [1,3,5...etc]
i = i+2;
end
which calculates the sum for i=1,2,3.... How do I change the increment of i?
##### 1 CommentShowHide None
Anga Vijay on 27 Jan 2021
This comment was flagged by Steven Lord
discuss the algorithm & execute the matlab programming for fixed increment learning algorithm for a classification problem with ‘n’ input features and 2 output classes (1/0), how to do for this problem ?

Sign in to comment.

### Answers (2)

Stephen Cobeldick on 9 May 2017
Edited: Stephen Cobeldick on 9 May 2017
i = 1:2:N
^ define the step size here!
The colon operator is clearly explained in the documentation:
##### 2 CommentsShowHide 1 older comment
Noman Rathore on 5 Dec 2018
Hello i am New researcher , and new to Matlab programming , but i understand the basius of programming , my querry is how i can use help and support for guidance for programming my own program. i most of the time do not find the useful help.
Nomi

Sign in to comment.

Phirime Monyeki on 10 Feb 2020
N = 100 ; % should be multiple of the number of parts you want
th = linspace(0,2*pi) ;
y = cos(th) ;
plot(th,y)
% divide the section into 5 equal parts
th1 = reshape(th,5,[]) ;
y1 = reshape(y,5,[])
##### 1 CommentShowHide None
Anga Vijay on 27 Jan 2021
discuss the algorithm & execute the matlab programming for fixed increment learning algorithm for a classification problem with ‘n’ input features and 2 output classes (1/0), how to do for this question.

Sign in to comment.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!