Antoine089
Antoine089

Reputation: 458

Convert Radian to Degrees Matlab

I'm trying to write a function that calculates Radian (Decimals) to Degrees.

For example

radiansToDegrees(1.5) = 1° 30' 00"

This is my logic:

  1. Using fix(), take the whole number before the decimal. This will be the degree.
  2. Take the remaining fraction (0.5 in the above case) and multiply by 60. From the answer, take the whole number before the comma. This becomes the minutes.
  3. Take the remaining fraction from step 2. (0 in the above case) and multiply by 60. This becomes the seconds.

I'm only able to reach step one. How do I retain only the fraction part of a number, especially if its something like this 0.8987724

Upvotes: 2

Views: 851

Answers (1)

Konstantin
Konstantin

Reputation: 3159

You may use functions from the Mapping Toolbox:

degrees = rad2deg(1.5)
dms = degrees2dms(degrees)
--------------------------------
dms = [85.0000, 56.0000, 37.2094]

Upvotes: 1

Related Questions