필터 지우기
필터 지우기

getting error in sloving atan function

조회 수: 1 (최근 30일)
Mahesh
Mahesh 2023년 11월 20일
답변: Walter Roberson 2023년 11월 20일
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