Hello everyone!
I have a problem but I can solve it. I would like to create a new vector with using if statement in a for loop. The problem is I dont' know how to call the new vector last member in the if statement. I know the first member the new vector. The first member is xn1.
I would like that if the if statement is true than add fn the last member the new vector. If false the new member is equal the last member.
I hope somebody can help me. Thanks a lot!
xn1=0.6;
xs=0.9:0.3:30;
fn=0.5;
fs=0.3;
r1=0.8;
r2=0.4;
xn=[];
for i=1:lenght(xs)
if (xs(i)+fs-r2)>=(xn(i-1)+fn/2)
% if true xn last member + fn
xn(i)=xn(i-1)+fn
else
% if false xn not change
xn(i)=xn(i-1)
end
end

 채택된 답변

David Hill
David Hill 2021년 11월 9일

0 개 추천

xn1=0.6;
xs=0.9:0.3:30;
fn=0.5;
fs=0.3;
r1=0.8;
r2=0.4;
xn=0;
for i=1:lenght(xs)
if (xs(i)+fs-re2)>=(xn(i)+fn/2)%have no idea what re2 is
xn(i+1)=xn(i)+fn;%cannot index xn(0)
else
xn(i+1)=xn(i);
end
end

댓글 수: 1

Zsolt Illés
Zsolt Illés 2021년 11월 9일
I corrected it re2 is r2. Thanks a lot. Now it's working

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2021년 11월 9일

댓글:

2021년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by