필터 지우기
필터 지우기

Decrementing for loop in MATLAB

조회 수: 188 (최근 30일)
Jatin Arora
Jatin Arora 2012년 11월 29일
편집: Dennis M 2021년 8월 24일
Hello everyone,
I am new to MATLAB programming and I want to use a for loop starting with an index 5 and reducing to 1
Example in C++ I can write for int i = 5;i<=1;i--)
how can this be implemented in MATLAB

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 29일
for k=5:-1:1
%do
end
  댓글 수: 1
Dennis M
Dennis M 2021년 8월 24일
편집: Dennis M 2021년 8월 24일
y = zeros(1,12);
for i = 1:12
y(i+1) = y(i) + ((5 - (4/50)*y(i)));
end
y
x = zeros(1,10);
for i = 10:-1:2
x(i-1) = x(i) + ((5 + (4/50)*x(i)));
end
x
Good Day,
May I ask how can I insert the start and stop variable on above code? for example I want to start in 17 to 30 or 15 to 2 with decrementing step.
Thanks and Regards,
Dennis

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

yagnesh
yagnesh 2012년 11월 29일
for i= 5:-1:1 %here we have used reverse for loop to overcome with error statement end
  댓글 수: 1
dhrumil sheth
dhrumil sheth 2016년 5월 25일
Very Good. It is really helpful for me

댓글을 달려면 로그인하십시오.


Jan
Jan 2012년 11월 29일
편집: Jan 2012년 11월 29일
It is always a good idea to read the documentation in case of questions:
There you find a corresponding example.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by