what is causing this error?

7 ビュー (過去 30 日間)
Ariana Garcia
Ariana Garcia 2019 年 3 月 18 日
回答済み: KSSV 2019 年 3 月 18 日
PosVecP = zeros(nMembersP, 3); %Initialize memory storage
UnitVecP = zeros(nMembersP, 3);
OppPosVecP = zeros(nMembersP, 3);
for (j = 1 : nMembersP)
SN = MemberP(j,1); %SN = start node
EN = MemberP(j,2); %EN = end node
PosVecP(j,:)= NodeP(EN,:)-NodeP(SN,:);
UnitVecP(j,:)=PosVecP(j,:)./norm(PosVecP(j,:));
OppUnitVecP(j,:)= -PosVecP(j,:)./norm(PosVecP(j,:));
%Finish this section to compute the position vector, length, unit vector,
%and negative unit vector for each member in the truss.
end % for j (members)
WHY DOES THIS ERROR MESSAGE KEEP POPPING UP WHEN I RUN SECTION
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in testruncp3 (line 92)
PosVecP(j,:)= NodeP(EN,:)-NodeP(SN,:);

回答 (1 件)

KSSV
KSSV 2019 年 3 月 18 日
Note that in matlab the indexing shoul dbe always a posittive integer or a logical. You are suing negative number, so error.
A = rand(10,1) ;
A(1) % no error
A(10) % no error
A(A>0.5) % logical allowed
A(0) % error, 0 double not allowed
A(-1) % error , negative not allowed
Put your code in debug mode and check the indices.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by