Reason: when the function isn’t on the MATLAB path or in pwd.
1. make sure that you are able to find the function using:
>> which rad2deg
‘rad2deg’ not found.
The return means It is not on the MATLAB path or in PWD. That is often unhelpful in this case – it tells you Matlab can’t find the file, which you knew already.
2. make sure that the file that matlab is finding (use which) requires the same type as the first argument you are actually passing.
Basically, Matlab looks for files in:
- The current directory (
- Directly in a directory on the path (to see the path, type
pathat the command line)
- In a directory named
@(whatever the class of the first argument is)that is in any directory above.
Radians To Degrees Conversion Function .
Converts the argument array from radians to degrees. The general syntax for its use is y = rad2deg(x)
Note that the output type will be the same as the input type, and that complex arguments are allowed. The output is not wrapped to [0,360).
Some known conversion factors
--> rad2deg(1) % one radian is about 57 degrees
--> rad2deg(pi/4) % should be 45 degrees
--> rad2deg(2*pi) % Note that this is 360 not 0 degrees
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.
radians(180) ans = 3.1416 degrees(pi/3) ans = 60
- deg = rad./(pi/180);
- ad = pi.*deg./180 ;