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 ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by