Error: ()-indexing must appear last in an index expression

I m getting this error while i try to execute this code
for i=1:n
for j=1:n
b1=bu(1,i)(j);
a1=(n*b1/(m(i)*m(j)));
p{1,i}=a1;
end
end
here bu is a cell of size(1,n)
m is an array of size(1,n)
p is i a cell of size(1,n)
please help
Thanks in advance!

 채택된 답변

Wayne King
Wayne King 2013년 1월 10일
I'm guessing you want:
for i=1:n
for j=1:n
b1=bu{i}(j);
a1=(n*b1/(m(i)*m(j)));
p{i}=a1;
end
end

댓글 수: 4

This gives a new error Index exceeds matrix dimensions as bu is (1,n).
And we cannot access cell element this way.
bu is a cell and i can access it as
bu{i,j}
or
bu{i,j}(i or j)
This is what i did..
No, your code was
b1=bu(1,i)(j);
with round brackets after bu, not curly brackets. () compared to {}

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by