It sounds as though you are trying to model a robot and then solve an inverse kinematics problem. This can be achieved by modeling the robot as a rigidBodyTree object and then using an inverse kinematics solver.
Create a Robot Model
To get started, create a robot model using the rigidBodyTree object. See the following documentation for details:
If, for example, you have DH parameters that define the dimensions you would like to use, you can closely follow the first example in the link above, or you can use the construction methods for more fine-grained model control. You can also import the robot from a URDF if you have one.
Create an Inverse Kinematics Solver
Next, you'll want to create a solver:
The following example illustrates both of these steps (creating a completely custom robot and solving IK for it) on a simple 2R mechanism, but it can easily be extended by adding more joints/links:
The IK Solver is not constrained by the number of joints/links. This example illustrates a similar concept with a more complex 6-DoF robot:
The following topic page provides a deeper overview of inverse kinematics in MATLAB:
You can find additional guidance in the documentation. For example, the following page lists some examples for robotic manipulators that might prove useful: