File Exchange Pick of the Week

Our best user submissions

degrees and radians

Bob's pick this week is degrees and radians by Richard Medlock.

These two helper functions are simple but useful. I don't know how many times I have needed to convert between radians and degrees over the years. (Hint: a lot!) For example, sometimes defining a frequency value in Hertz is more convenient for humans, but conversion to radian frequency is generally needed by the computer at some point.

f0 = 60;         %frequency (Hz)
w0 = f0*pi/180;  %natural frequency (rad)

The conversion factor is not difficult, but it can be a workflow distraction nonetheless. Hence, Richard's utility functions to do the conversion for you.

ans =
ans =

I tend to dislike magic numbers, particularly in complex calculations. So I can see helper functions like these making code more readable. Magic numbers that appear many times throughout a program can also be prone to logical errors if I mistype a value somewhere. Those types of problems can be difficult to track down. Also, having conversion code centralized in one place can pay dividends in reusability and testability.


Published with MATLAB® 7.10

  • print


コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。