フィルターのクリア

Array indices must be positive integers or logical values error

1 回表示 (過去 30 日間)
Haren Sunil Panchal
Haren Sunil Panchal 2021 年 2 月 17 日
%HW4 Q2-Vector Loop solution
r2=1; r3=4;
theta2=60;
X = (2*r2((cosd(0)*cosd(theta2))));
B=r2^2-r3^2;
%Case 1 - signma=+1
sigma=1;
r1=(-(-X)+sigma*sqrt(X^2-4*B))/2;
theta3=atand((-r2*sind(theta2))/r1*cosd(0)-r2*cosd(theta2));
%Case 2 - sigma=-1
sigma=-1;
r1=(-(-X)+sigma*sqrt(X^2-4*B))/2;
theta3(2)=atand((-r2*sind(theta2))/r1*cosd(0)-r2*cosd(theta2));
The error is on line 4 for 'X' variable
  2 件のコメント
the cyclist
the cyclist 2021 年 2 月 17 日
FYI, I edited your question to use the "code" format from the toolbar, to make it more readable. Next time, please take a look at doing that yourself.
Haren Sunil Panchal
Haren Sunil Panchal 2021 年 2 月 17 日
Ok, Sorry for that

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2021 年 2 月 17 日
編集済み: the cyclist 2021 年 2 月 17 日
You need
X = (2*r2*((cosd(0)*cosd(theta2))));
instead of
X = (2*r2((cosd(0)*cosd(theta2))));
(Note that I used r2* instead of just r2.)
MATLAB needs the explicit multiplication sign there, to distinguish the syntax from indexing a variable (which is why it threw that error).
  1 件のコメント
Haren Sunil Panchal
Haren Sunil Panchal 2021 年 2 月 17 日
Thank you. This helped me resolve the issue.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by