How to reduce angle values in a range between 0 and 360 deg?
25 views (last 30 days)
Show older comments
Hi everyone! I have obtained the angles alpha, beta and gamma in deg. However I would like to make a plot with values of gamma in a range between 0 and 360 deg (a sort of step-plot). Can anyone help me?
%B = load('PosRel.txt');
B = readmatrix('PosRelORF.csv');
time = B(:,1);
num_times = size(time,1);
%assegno valori iniziali degli angoli di Eulero
alpha0 = convang(5,'deg','rad');
beta0 = convang(5,'deg','rad');
gamma0 = convang(5,'deg','rad');
vAlphaBetaGamma0 = [alpha0, beta0, gamma0];
[vTime, vAlphaBetaGamma] = ode45(@funzione,time,vAlphaBetaGamma0);
alpha = vAlphaBetaGamma(:,1);
beta = vAlphaBetaGamma(:,2);
gamma = vAlphaBetaGamma(:,3);
alpha = convang(alpha,'rad','deg');
beta = convang(beta,'rad','deg');
gamma = convang (gamma,'rad','deg');
figure
plot(vTime,alpha,'k',vTime,beta,'r', vTime,gamma,'b');
legend('alpha','beta','gamma');
xlabel('Time (seconds');
ylabel('Angles (deg)');
function angularvelocities=funzione(t,attitudeangles)
angularvelocities = [0;0;0.4]; %rad/sec
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/783658/image.jpeg)
0 Comments
Accepted Answer
Star Strider
on 30 Oct 2021
I am not certain what the desired result is.
Something like this came up once before, and since wrap2pi and wrap2360 are available here (I do not have the Mapping Toolbox), I wrote a function to emulate both, comparing it to those functions while experimenting with the results here. (Replace ‘360’ with ‘2*pi’ and ‘180’ wiith ‘pi’ to get the wrap2pi equivalent, or other values to get different behaviour.)
See if this produces the desired result —
a = linspace(-720, 720);
figure
plot(a, wrap_180(a))
grid
figure
plot(a, wrap_360(a))
grid
function wP1 = wrap_180(P1) % EMulates 'wrap2180'
mf = mod(P1,360);
wP1 = mf.*(mf<=180) + (mf-360).*(mf>180);
end
function wP1 = wrap_360(P1) % EMulates 'wrap2360'
mf = mod(P1,720);
wP1 = mf.*(mf<=360) + (mf-720).*(mf>360);
end
.
2 Comments
Star Strider
on 30 Oct 2021
My calculations do not agree with yours.
I get 19 revolutions, not 38 —
av = 0.4; % Angular Velocity (rad/s)
tvl = 600; % Record Length (s)
rrevs = av*tvl % Revolutions (rad)
drevs = string(rad2deg(rrevs)) % Revolutions (°) ('string' Call To Show PRecision)
tv = linspace(0, tvl, tvl); % Time Vector (s)
tot_revs = rad2deg(av) * tv; % Total Revolutions In 'tvl'
% endrevs = tot_revs(end)
Nr_revs = nnz(islocalmax(wrap_360(tot_revs))) % Total Number Of Revolutions (Counts Peaks)
figure
subplot(2,1,1)
plot(tv, tot_revs)
grid
xlabel('Time (s)')
ylabel('Degrees')
subplot(2,1,2)
plot(tv, wrap_360(tot_revs))
grid
xlabel('Time (s)')
ylabel('Degrees')
function wP1 = wrap_360(P1) % Emulates 'wrapTo360'
mf = mod(P1,720);
wP1 = mf.*(mf<=360) + (mf-720).*(mf>360);
end
I cannot test my code with the actual data without the actual data.
.
More Answers (1)
Walter Roberson
on 29 Oct 2021
mask = 0 <= gamma & gamma <= 360;
plot(vTime(mask), alpha(mask), 'k', vTime(mask), beta, 'r', vTime(mask), gamma(mask), 'b');
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!