필터 지우기
필터 지우기

Why does my loop only run once

조회 수: 8 (최근 30일)
Raquel Terrer van Gool
Raquel Terrer van Gool 2020년 4월 14일
댓글: Raquel Terrer van Gool 2020년 4월 14일
function I=trapezoidal(f,a,b,n)
h=(b-a)/n; % length of the interval
total=0;
x=a;
fa=f;
x=b;
fb=f;
for i=n
x=i;
fn=f+total
total=fn
end
I=fa+fb+2*fn;
end

채택된 답변

Peng Li
Peng Li 2020년 4월 14일
I assume that your parameter n is a scalar? If you want to let your script loop from 1 through n, you use for i = 1:n.

추가 답변 (0개)

카테고리

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