indexing must appear last in an index expression ERROR

6 ビュー (過去 30 日間)
Hamid
Hamid 2014 年 12 月 12 日
コメント済み: Hamid 2014 年 12 月 12 日
Hi everybody,
I get this error : ()-indexing must appear last in an index expression. Line: available(b,6)... Column: 17
also I have this warning at that line : can not call or index into a temporary array.
for i=1:ne
Le(i)=sqrt((Ex(i,1)-Ex(i,2))^2+(Ey(i,1)-Ey(i,2))^2+(Ez(i,1)-Ez(i,2))^2);
if Le(i)==0
j=+j1;
else
u=u+1;
end
Le(i)/200<available(i,6);
available(b,6)=available(i,6)(min(find(available(i,6)*200>Le(i)==1)));
Ep(u,:)=available(b,:);
end
I will be very thankful for any suggestion.

採用された回答

Guillaume
Guillaume 2014 年 12 月 12 日
In matlab you can't chain indexing and as the error message tells you, you can't index temporaries. So you can't do
m(SomeIndexingOperation)(SomeOtherIndexingOperation)
m(SomeIndexingOperation) is a temporary, and you can't index it further without assigning it to a variabe. So to resolve your problem, you first need to assign available(i,6) to a variable before ou can index into it:
temp = available(i, 6)
available(b, 6) = temp(min(...
That's one issue with your code. There are unfortunately more:
1.
min(find(something))
is the same as
find(something, 1) %but this is much faster
2. The code inside your find is suspicious. You usually don't have operators > and == in the same expression. As it is since the expression before the == is either 0 or 1 the == 1 does not do anything, so your expression is the same as
available(i,6)*200>Le(i)
3. The line
Le(i)/200<available(i,6);
does not do or assign anything since the result is not assigned to anything.
  10 件のコメント
Guillaume
Guillaume 2014 年 12 月 12 日
Use the second return value of min, which will be the row index where the minimum is found
[~, minidx] = min(available(available(:, 6) > Le(i)/200, 6));
minrow = available(minidx, :)
Hamid
Hamid 2014 年 12 月 12 日
Beautiful, thanks a lot

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 12 日
You probably forgot an operator, maybe a prod *
available(b,6)=available(i,6)*(min(find(available(i,6)*200>Le(i)==1)));
  1 件のコメント
Hamid
Hamid 2014 年 12 月 12 日
Thank you Azzi,
available is a 128*6 matrix, I have available(i,6)<Le(i)/200 and I want available(i,6) to be minimum.
after that I want to assign available(i,6) minimums to available(b,6) , while in this try I got that error.
Thanks.

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

カテゴリ

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