- #1
Zoobie
- 3
- 0
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.
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
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