while loop error with conditional statment

조회 수: 1 (최근 30일)
PetronasAMG
PetronasAMG 2018년 2월 19일
답변: Basil C. 2018년 2월 19일
i %ignore this i code starts from below
interval = 1.2
x_int = 0:intereval:c
i=1
while x_int(i) <= c
ya(i) = ((5*c)*(TT/100))*((0.2969*sqrt(x_int(i)/c))-(0.126*(x_int(i)/c))-...
(0.3516*(x_int(i)/c)^2)+(0.2843*(x_int(i)/c)^3)-(0.1015*(x_int(i)/c)^4));
yb(i)= -((5*c)*(TT/100))*((0.2969*sqrt(x_int(i)/c))-(0.126*(x_int(i)/c))-...
(0.3516*(x_int(i)/c)^2)+(0.2843*(x_int(i)/c)^3)-(0.1015*(x_int(i)/c)^4));
i=i+1
end
Here c can be any whole number (assuming it's bigger than its interval). when i run this i get an error saying Index exceeds matrix dimensions. at while x_int(i) <= c Please help!

답변 (1개)

Basil C.
Basil C. 2018년 2월 19일
OR you could just modify your WHILE loop condition as :
while (x_int(i) <= c && i<length(x_int))

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by