MATLAB Answers

0

for loop in matlab

Asked by hang dong on 10 Jun 2019
Latest activity Commented on by Utkarsh Belwal on 10 Jun 2019
How can the for loop start to start from the value 0?

  0 Comments

Sign in to comment.

1 Answer

Answer by Utkarsh Belwal on 10 Jun 2019

% Here is a for loop which starts from 0 and ends at 100.
for i = 0 : 100
% Your Code
end

  3 Comments

hang dong on 10 Jun 2019
If you use a for loop for an array, you cannot get the value 0. Help me!
Walter Roberson
on 10 Jun 2019
You can never index at 0 in MATLAB, regardless of what your loop starts at.
for i = 0 : 100
y(i+1) = x(i).^2 + 5;
end
MATLAB uses 1 based indexing not zero based so you can not access zero index in MATLAB.

Sign in to comment.