Array indicates must be positive integers or logical values

1 回表示 (過去 30 日間)
Hamza Khaliq
Hamza Khaliq 2020 年 2 月 3 日
編集済み: Sridhar SG 2020 年 2 月 3 日
%question 3
clf
t= 0:0.01:2;
y3= 8*sin(20*pi*t)+8*sin(22*pi*t);
plot(t,y3)
xlabel('t')
ylabel('y3')
%question 4
clf
t= 0:0.01:2;
expA= exp(-1.2*t);
y4= y3.*expA
plot(t,y4)
xlabel('t')
ylabel('y4')
%question 5
clf
H= [34 -56 23];
J=[9 12 26];
squrH = H.^2;
MagH = sqrt(sum(squrH))
squrJ = J.^2;
MagJ= sqrt(sum(squrJ))
Angle =acos(sum(H.*J) / (sqrt(sum(H.^2)) * sqrt(sum(J.^2))))
angeldeg = Angle*180/pi
  1 件のコメント
Adam Danz
Adam Danz 2020 年 2 月 3 日
The code you provided does not produce the error in the title.

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

回答 (3 件)

Image Analyst
Image Analyst 2020 年 2 月 3 日

Star Strider
Star Strider 2020 年 2 月 3 日
Taking a wild guess, you likely have a variable named plot or sum (or something similar) that is overshadowing a MATLAB function with the same name.
Without the complete error message (all the red text copied from your Command Window and pasted to a Comment here), it is not possible to determine what that overshadowed function is.
Assuming it is sum, the way to determine that is to type this in a script or your Command Window:
which sum -all
If the first line returned is:
sum is a variable.
you have found the problem.
The solution is to rename the variable to something that makes sense in the context of your code.

Sridhar SG
Sridhar SG 2020 年 2 月 3 日
編集済み: Sridhar SG 2020 年 2 月 3 日
Your code got successfully executed
MATLAB allows storing of any type of value inside the arrays, only the index values of array cannot be fractional numbers, negative integers, zero or complex/imaginary numbers

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by