getting error in sloving atan function

1 次查看(过去 30 天)
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 个评论
DGM
DGM 2023-11-20
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-11-20
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by