Create a new vector
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!