how do i jump to a previous line in a matlab program

조회 수: 40 (최근 30일)
Dilesh Maharjan
Dilesh Maharjan 2013년 11월 22일
답변: Iosif 2022년 11월 13일
clc
tini=[21;26;29;30;23];
x= [1,2,3,0,0;3 6 -3 tini(3) 3;0,0, -2,-7,4;0,0,8,-3,tini(4);4,-5,8,0,0];
invx= inv(x);
a= [9;-3;21;tini(4);-23];
t=invx*a;
x=t-tini;
minx = min (x)
if abs(minx)>=1
tini=t;
% i need to go to line 4 and replace tini values with recent ones
else
fprintf ('your final temp is\n')
t
end

답변 (3개)

Walter Roberson
Walter Roberson 2013년 11월 22일
You cannot jump to previous lines. Use a structure such as
tini = ....
while true
x = ....
...
if abs(minx) < 1 %reversed condition
disp(...)
break
end
end

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 22일
I am not sure that your code converge, maybe you want
clc
tini=[21;26;29;30;23];
minx=10;
while minx>=1
x= [1,2,3,0,0;3 6 -3 tini(3) 3;0,0, -2,-7,4;0,0,8,-3,tini(4);4,-5,8,0,0];
invx= inv(x);
a= [9;-3;21;tini(4);-23];
t=invx*a;
x=t-tini;
minx = min (abs(x)); % I changed this line
tini=t;
end
fprintf ('your final temp is\n')
t
  댓글 수: 1
Dilesh Maharjan
Dilesh Maharjan 2013년 11월 25일
thank you very much for your help.. this is what i was trying to do..

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


Iosif
Iosif 2022년 11월 13일
D=input ('Βαθος νερου σε m ')
W=input ('Βαρος ανα μοναδα μηκους της γραμμης αγκυρωσης στο νερο σε N/m ')
Hex=input ('εξωτερικη φορτηση σε kn ')
dx=input ('οριζοντια μετατοπιση σε m ')
if dx/D>=0.3 && dx/D<=0.6
else
disp ('Δωσε διαφορετικη τιμη για το dx')
dx=input ('οριζοντια μετατοπιση σε m ')
end
I want to make my programm go to if after else and run that lines again until if line is satisfied

카테고리

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