# MatLab Code for Baseball Not Working

A semicolon at the end of a MATLAB code line stops MATLAB from printing the result of the line. You want to do that so it will not fill the screen with data on lines that you already trust and do not need to see the results. When you are debugging, you might want to remove a semicolon at the end of a MATLAB line to see the results and make sure they are as expected. For instance, to see what is going on in your definition of t and size(t), remove the trailing semicolons to see that t is a 1xN matrix and the size function sets i and j to the dimensions. 'tMin:dt:tMax' is a loop from tMin to tMax in steps of dt.

Matlab:
>> tMin=0;
>> tMax=5;
>> dt = 1;
>> t = tMin:dt:tMax

t =

0     1     2     3     4     5

>> [j,k] = size(t)

j =

1

k =

6

I remove trailing semicolons to debug lines and then put them back when I'm confident of that line.

PS. A semicolon inside a matrix definition is different. It starts a new matrix definition row. There may be other uses of the semicolon inside a MATLAB line; I can't think of any now.

excellent! I definitely do not want that :D

@FactChecker
shoot, I was predefining the matrix for my new code, and I forgot the semicolon. so 10,000 zeroes are being shot at me lol

@FactChecker
in true basic there is a command
Code:
mat redim x(i),y(i)

that is used to resize the dimensions of the matrices to a different value. So the matrix is predefined to be set at 5000, and at the end, the program figures out that only 1000 spaces are needed. so that command resizes the matrices.

is there something similar in MatLab?

edit:
Code:
x() and y() are the position of the projectile
dt = time step v_init = initial speed theta - launch angle
B_m = proportional to drag force= B2/m
sub calculate(x(),y(),dt,v_init,theta,B_m)
option angle degrees ! use degrees rather than radians
x{l) = 0
y(l) = 0
vx = v_init * cos(theta)
vy = v_init * sin(theta)
! initial velocity components
nmax = size(x) ! this is the number of elements in the array x()

for i = 2 to nmax
x(i) = x(i-1) + vx * dt
y(i) = y(i-1) + vy * dt
f = B_m * sqr(vxA2 + vyA2)
vy = vy - 9.8 * dt - f * vy * dt
vx = vx - f * vx * dt
if y(i) <= 0 then exit for

next i
a= -y(i) / y(i-1)
x(i) = (x(i) + a*x(i-1)) / (l+a)
y(i) = 0
mat redim x(i),y(i)
end sub
[/quote]

Last edited: