command for delaying matlab to execute a certain line

hello im doing an iteration and everytime i execute my code it brings out and error
clc
clear
format longg
gama=0.75;
ppc=667;
tpc=408;
pts=2500;
tts=35+460;
tws=245+460;
l=10000;
theta=0;
x=10;
pws=(pts)+(0.25*(pts/100))*((l*cos(theta))/(100))
for i=1:x
pavg(i)=(pws+pts)/2
tavg=(tws+tts)/2
tpr=tavg/tpc
ppr(i)=pavg(i)/ppc
z(i)=input('enter z: ');
s(i)=(0.0375*gama*l*cos(theta))/(z(i)*tavg)
pws=pts*exp(s(i)/2)
if s(i)==s(i-1);
display('done')
break
else
display('u need more iterations')
end
end
the error comes out because matlab executes the if statement before another value for "s" has been calculated i want it to wait till a second value of "s" is calculated to execute the if loop i know this code is kinda amateur but bare with me please im new to matlab coding, and if u have any suggestion on a simplest form of this iteration please do help.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 1일

0 개 추천

Matlab execute the lines of your code one after another. The if statement will be executed after the calculation of s(i). What is the error message? have you tried to debug your code?

댓글 수: 3

mohamed
mohamed 2016년 4월 1일
편집: mohamed 2016년 4월 1일
this is the error message
Subscript indices must either be real positive integers or logicals.
Error in prob6 (line 23)
if s(i)==s(i-1);
and what is debugging?
You need to initialize s, and the for loop should start at i=2, because if i is equal to 1, you can't write s(i)==s(i-1), i-1=0 is not allowed by Matlab
mohamed
mohamed 2016년 4월 1일
편집: mohamed 2016년 4월 1일
how do you suggest i initialize "s" i tried coping the rules under the for loop and calculating them at first then starting the code at i=2:x, it didnt work it only gave me 1 value for pws the new one every time i enter a value for z

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

질문:

2016년 4월 1일

편집:

2016년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by