Hi again! Working with an if/then statement and running into trouble. Here's my code.(adsbygoogle = window.adsbygoogle || []).push({});

And here is the result:Code (Text):a=2;

N = input('Enter the number of applied loads:');

for i=1:N

L(i)=input('Enter the force of the applied load in kN:');

D(i)=input('Enter the position of the applied load in meters:');

end

if D(i) > a

Z(i)=L(i)*-1

else Z(i)=L(i)

end

Why is Z(1) coming out zero? With my if/then statement, what I want is if D>a, then L= -1*L. If not, it should just stay the same, not return a zero.Code (Text):Enter the number of applied loads:2

Enter the force of the applied load in kN:1

Enter the position of the applied load in meters:1

Enter the force of the applied load in kN:3

Enter the position of the applied load in meters:3

Z =

0 -3

>> D

D =

1 3

>> L

L =

1 3

Any ideas?

edit: Interesting....

What's going on?!Code (Text):>> projectdebug

Enter the number of applied loads:10

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Enter the force of the applied load in kN:5

Enter the position of the applied load in meters:5

Z =

0 0 0 0 0 0 0 0 0 -5

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB giving 0 value for if/then statement

**Physics Forums | Science Articles, Homework Help, Discussion**