Borrar filtros
Borrar filtros

How to convert radians to degrees?

17 visualizaciones (últimos 30 días)
Rohan Repale
Rohan Repale el 21 de Mayo de 2013
Comentada: Ivan-V-Timofeev el 4 de Nov. de 2014
Hi, I have this code,
clear all, close all, clc,
r = 0.08;
t = 2;
for n = 1:180,
M(1,n) = r*cos(t); %x length from center
M(2,n) = r*sin(t); %y length from center
t = t+2;
end
It is meant to find the x,y distance from the center of a circle with fixed radius (Basically calculating x,y coordinates of circumference).
However the coordinates are coming wrong and it is because Matlab is performing calculations in radians rather than in degrees. (I cross checked the values with calculator) And I don't know how to convert to radians, and none of the forum results made sense to me.
Thanks, Rohan

Respuestas (3)

José-Luis
José-Luis el 21 de Mayo de 2013
Editada: José-Luis el 21 de Mayo de 2013
There is a built in function for that:
doc deg2rad
But it is rather trivial to implement it yourself:
myTrans = @(x) x./360.*(2.*pi());
myTrans(180)
ans =
3.1416
  6 comentarios
Rohan Repale
Rohan Repale el 21 de Mayo de 2013
@James, mathematically speaking the other suggestions must work as well, but the output was not matching my expected output. But when I used sind and cosd, it worked perfect. Maybe I was not doing it right. Anyways thanks for the help
Ivan-V-Timofeev
Ivan-V-Timofeev el 4 de Nov. de 2014
deg2rad
It does not work without toolbox > geo > private > deg2rad.m http://mooring.ucsd.edu/software/matlab/doc/toolbox/geo/private/deg2rad.html

Iniciar sesión para comentar.


Iain
Iain el 21 de Mayo de 2013
Degrees = 180 * radians / pi.
Rearrange as needed ;)
  6 comentarios
Iain
Iain el 21 de Mayo de 2013
Radians = degrees * (pi/180)
"t" is in degrees, and you want it in radians when put into cos and sin.
cos(t * (pi/180)) and sin(t * (pi/180)) is the conversion rearranged as needed, AND put in the right place...
José-Luis
José-Luis el 21 de Mayo de 2013
Doesn't seem to work... How? Please show what you mean.

Iniciar sesión para comentar.


per isakson
per isakson el 21 de Mayo de 2013

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by