# Transform angles that are -180 to +180 to angles that are in the 0-360 degree range?

83 visualizzazioni (ultimi 30 giorni)
Kylie Davis il 1 Giu 2016
Risposto: theodore panagos il 5 Dic 2018
I am implementing a vector coding technique in matlab using the atan2d(diff(y),diff(x)) function, but the results are from -180 to +180 and I would like to have a 0-360 range. I tried to input an if statement for angles < 0 to have 360 added to them, but I couldn't get it to work. It is possible that I just didn't write the statement correctly, but I would appreciate any tips or advice.
##### 2 CommentiMostra NessunoNascondi Nessuno
dpb il 1 Giu 2016
"It is possible that I just didn't write the statement correctly, but I would appreciate any tips or advice."
Well, it's a little tough to comment on what we can't see...what did you try?
Kylie Davis il 1 Giu 2016
Sorry about that. I tried: if x < 0 x = x+360 end
But the other difficulty I am having is that I have so many data sets that I need to apply that to. I have hip, knee, and ankle joint angle data for both limbs of 18 subjects. So I need to have an if statement correcting the negative angles for 36 different sets.

Accedi per commentare.

### Risposta accettata

Star Strider il 1 Giu 2016
This is my little anonymous function that I use for such problems:
Angles360 = @(a) rem(360+a, 360); % For ‘atan2d’
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Kylie Davis il 1 Giu 2016
I think I got it to work. Thanks so much!
Star Strider il 1 Giu 2016
My pleasure!
It’s an anonymous function, and works like any other function. Just put it at the beginning of your code, then call it as:
Angles360 = @(a) rem(360+a, 360); % For ‘atan2d’
x = randi(9, 5, 1); % Create Data
y = randi(9, 5, 1); % Create Data
theta = atan2d(diff(y),diff(x));
theta360 = Angles360(theta);

Accedi per commentare.

### Più risposte (1)

theodore panagos il 5 Dic 2018
A formula to calculate an angle counter clockwise from x positive to 360 degrees:
f(x,y)=180-90*(1+sign(x))* (1-sign(y^2))-45*(2+sign(x)*sign(y)
-180/pi()*sign(x*y)*atan((abs(x)-abs(y))/(absx)+abs(y)))
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Analysis of Variance and Covariance in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by