Effacer les filtres
Effacer les filtres

getting error in sloving atan function

1 vue (au cours des 30 derniers jours)
Mahesh
Mahesh le 20 Nov 2023
Hi,i want to create 1x100 double vector, but ended up in getting an error "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side". The code is as follows
for i = 1:10
y(99+1)=atan([-1.74908051612442,0.591783255482434])*180/pi
end
Please anyone help me
  1 commentaire
DGM
DGM le 20 Nov 2023
This doesn't make sense on multiple levels. You want a 1x100 vector, but your loop only iterates 10 times, and it only attempts a single assignment which is completely independent of the loop. The loop serves no purpose.
The error is because the RHS of the assignment is a scalar, but the LHS is a vector that never changes.
% y(100) % is a scalar
% this is a 2-element vector
atan([-1.74908051612442,0.591783255482434])*180/pi
ans = 1×2
-60.2421 30.6163
Maybe you meant to use atan2() or atan2d()?
... but the loop still doesn't make sense, since nothing changes.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Nov 2023
The two-argument version of atan is named atan2
for i = 1:10
y(90+i)=atan2(-1.74908051612442,0.591783255482434)*180/pi;
end
format long
y(89:93)
ans = 1×5
0 0 -71.307284328925377 -71.307284328925377 -71.307284328925377

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by