フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by