Clear Filters
Clear Filters

getting error in sloving atan function

1 view (last 30 days)
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 Comment
DGM
DGM on 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!