I have a program that needs to print out a formated table of time x distance and ydistance. I got everything written except for figureing out how to print out formatted tables could somebody help me here is the code.(adsbygoogle = window.adsbygoogle || []).push({});

%Constants and initial values

g = -9.8;

conv = (pi/180);

%Get users inputs in the following order:distance,velocity,angle

try

distance = input ('Please enter the distance to your target: (meters) \n');

m = Distance <= 0;

if m == 1

disp ('::FATAL ERROR: Distance cannot be < or = to zero, goodbye')

break

end

catch ME

end

try

velocity = input ('Please enter initial velocity of the projectile: (m/s) \n');

m = velocity <= 0;

if m == 1

disp ('::FATAL ERROR: Velocity cannot be < or = to zero, goodbye')

break

end

catch ME

end

try

theta = input ('Please enter an angle (degrees) between 0 and 90: \n');

m = theta < 0 | Theta > 90;

if m == 1

disp ('::FATAL ERROR: Angle cannot be < or = to zero, goodbye')

break

end

catch ME

end

%Calculate initial x and y velocitys, time, and range

voy = velocity*sin(theta*conv);

vox = velocity*cos(theta*conv);

time = -2*(voy / g);

range = (vox*time)

%Show how far bag traveled

fprintf ('The bean bag traveled a total of %6.2f meters \n',range)

%Create masks to determine how close projectile was to target

ma = (range-2.5 <= Distance && Distance <= range+2.5);

mb = (range > Distance-2.5);

mc = (range < Distance+2.5);

%Interpret masks

if ma == 1

fprintf ('Your bag hit the target right on!! GOOD AIM')

elseif mb == 1

fprintf ('so your bean bag traveled long %6.2f meters \n', abs(range - distance))

elseif mc == 1

fprintf ('so your bean bag traveled short %6.2f meters \n', abs(distance - range))

end

disp 'Please press enter to see (x,y) coordinates as a funtion of time:'

pause

%TABLE/GRAPH%

xpos = 0; %Set starting location at (x,y)=(0,0)

ypos = 0;

t=0; %Random incrementing variable(represents time).

for t=0:.1:100

t=t+1;

vy = voy + (g*t);

xpos = xpos + (vox*.1);

ypos = ypos + (voy*.1);

out = [t' xpos' ypos']

fprintf ( 'The x value is %6.2d and y value is %6.2d n\',out(t,

if( ypos < 0 )

break;

end

end

**Physics Forums - The Fusion of Science and Community**

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

# Matlab and tables

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - Matlab tables | Date |
---|---|

Python How can I run Python by getting values from Matlab | Mar 7, 2018 |

What is each step of this Matlab program doing? | Feb 21, 2018 |

C/++/# Help with MATLAB code? | Feb 9, 2018 |

Numerical Integration with variable limits MATLAB | Jan 15, 2018 |

Merging matrix into a table - Matlab question | Dec 29, 2010 |

**Physics Forums - The Fusion of Science and Community**