indexing must appear last in an index expression ERROR

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.

 Accepted Answer

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 Comments

Thank you my friend,
I changed it
temp=available(i,6);
available(b,6)=temp(find(temp>Le(i)/200, 1 ));
But I get this error :
??? Subscript indices must either be real positive integers or logicals
what should I do now?
Most likely b is not a positive integer.
However, note that I've just read your comment to Azzi, and the question you've linked. It's unfortunate that the answer you've been given in that question is utterly wrong (I've now commented and answered that question).
But also, I don't understand what you're trying to do here. If available is a matrix, available(i, 6) is a scalar, just one number. So there's no minimum or maximum to speak of.
actually there is min & max here.
for example
r=[1 1.1 1.2 1.3 1.4 1.5]
r>L/200 L=210 therefore r>1.05 and from 1.1 until 1.5 can handle this condition but 1.1 is minimum;
I need a code just like that, what do you recommend Guillaume?
I made a mistake and I think available(i,6) must be available(:,6) so we have a 128*1 matrix and I want to choose minimum,but I don't know how????!!!
what do you recommend Guillaume?
Thank you very much
Right, that makes a lot more sense. This will do:
available(b, 6) = min(available(available(:, 6) > Le(i)/200, 6));
Thank you dear, I think this is it but how can I solve this error that I got here.
??? Subscript indices must either be real positive integers or logicals.
As I said, most likely b is not a real positive integer. What is the value of b?
you were right b is not positive,
I have another problem and I will be very grateful if you help me out.
for example available is 3*6 matrix
available=[1 2 3 4 5 6;7 8 9 10 11 12;13 14 15 16 17 18]
assume ; x=min(available(available(:, 6) > Le(i)/200, 6));
x=12
I want another matrix which has complete row of 12 (available row 2)
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, :)
Beautiful, thanks a lot

Sign in to comment.

More Answers (1)

You probably forgot an operator, maybe a prod *
available(b,6)=available(i,6)*(min(find(available(i,6)*200>Le(i)==1)));

1 Comment

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.

Sign in to comment.

Categories

Tags

Asked:

on 12 Dec 2014

Commented:

on 12 Dec 2014

Community Treasure Hunt

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

Start Hunting!