I was tasked with creating a simple program to model the solar system using Matlab. One step in the way I wanted to do this was by making a "planet" class that stored the x,y,z position, and the x,y,z velocity.(adsbygoogle = window.adsbygoogle || []).push({});

One of the methods, then, would be something to that took in another "planet" object and computed the distance between them. This is easy enough to do, but I can't figure out what the syntax is.

I have:

function [dist] = distanceTo(obj)

dist = sqrt(abs(obj.x - x)^2 + abs(obj.y- y)^2 + abs(obj.z-z)^2);

end

My intention here is that obj will be an inputted planet, and typing obj.x will give you its x-value. This however isn't the case, and whenever I try to run it I get a "Too many inputs error"

Can anyone help me figure out the correct syntax? Thanks for any help and happy holidays

**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 question about Methods

Loading...

Similar Threads for MatLab question Methods |
---|

MATLAB MATLAB: forces acting on an object |

MATLAB Matlab histogram |

MATLAB Sovling Bernoulli's differential equation in matlab? |

MATLAB Matlab-like software |

MATLAB Matlab data into bins |

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