I am trying to write code to determine when two precession angles match. Matlab keeps skipping to the last else statement regardless of which elseif statement should be taking precedence.
prec1 = rad2deg(acos(C21./sin(deg2rad(nutation))));
Unrecognized function or variable 'C21'.
prec2 = rad2deg(asin(C31./sin(deg2rad(nutation))));
if abs(prec1 - prec2) < 10^-3
prec = prec1;
elseif abs(prec1 - (180 - prec2))< 10^-3
prec = prec1;
elseif abs((360 - prec1) - prec2) < 10^-3
prec = prec2;
else
prec = 360 - prec1;
end

4 commentaires

Image Analyst
Image Analyst le 20 Fév 2024
That's not what happens when we run your code. We get that C21 is not defined. What is prec1 and prec2, or what is C21, C31, and nutation?
Adam Danz
Adam Danz le 20 Fév 2024
We can't follow the logic without knowing C21, C31, and while we're at it, nutation.
Madeleine
Madeleine le 20 Fév 2024
C21, C23, and nutation are arrays that contain ten values calculated earlier in the code.
C12 and C23 are elements of a direction cosine matrix for a two body 1-3-1 rotation sequence and nutation is the angle about body fixed axis u1. precession is the angle about body fixed axis u3.
Madeleine
Madeleine le 20 Fév 2024
C12 =
0
0.5207
-0.2255
0.6599
0.0813
0.4857
-0.0558
-0.3070
-0.2298
-0.7950
C23 =
0
0.4887
0.0624
-0.3257
0.0516
-0.7995
0.3638
-0.7010
0.2401
-0.6821
nutation =
0
116.6697
53.6137
79.6703
102.4619
32.9411
127.0446
18.0036
103.4862
69.9394

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 20 Fév 2024

0 votes

You would get that behavior if prec1 or prec2 are non-scalar and it does not happen that all of the values pass the tests.

1 commentaire

Madeleine
Madeleine le 21 Fév 2024
How do i make my variables scalar. I tried using ANY and ALL functions but it I still get a non-scalar error

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator dans Centre d'aide et File Exchange

Produits

Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by