Attempted to access indx(1); index out of bounds because numel(indx)=0.

조회 수: 4 (최근 30일)
Dear all, WHAT IS THE HELL OF THIS ERROR??????
what can I do??
function [Ex,Ey,Ez]=coordxtr(Edof,Coord,Dof,nen)
%[Ex,Ey,Ez]=coordxtr(Edof,Coord,Dof,nen)
[nel,dum]=size(Edof);
ned=dum-1;
[n,nsd]=size(Coord);
[n,nd]=size(Dof);
nend=ned/nen;
%
for i = 1:nel
nodnum=zeros(1,nen);
for j = 1:nen
check=Dof(:,1:nend)-ones(n,1)*Edof(i,(j-1)*nend+2:j*nend+1);
[indx,dum]=find(check==0);
nodnum(j)=indx(1);
end
%
Ex(i,:)=Coord(nodnum,1)';
if nsd>1
Ey(i,:)=Coord(nodnum,2)';
end
if nsd>2
Ez(i,:)=Coord(nodnum,3)';
end
end
%--------------------------end--------------------------------
  댓글 수: 2
Matz Johansson Bergström
Matz Johansson Bergström 2014년 8월 17일
Do you have an example of inputs to the function that gives this error?
Hamid
Hamid 2014년 8월 17일
Thank you Matz,
yes, I do. nen=3
I debugged and this tip comes out.
Please help me out Matz, I am awful
thanks

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

채택된 답변

Matz Johansson Bergström
Matz Johansson Bergström 2014년 8월 17일
It would be better if you could give us an example of all the arguments, so we can try it out for ourselves. I know what the immediate problem is but it is more important to understand why it happens.
You are trying to index a vector containing no elements, so the question is: why is this?
To answer the other error you got, the problem seem to be that the type of indices you are passing to the vector is not real positive integers . If you followed Ahmet's solution, you will be passing a 0 as an index, which is not allowed in Matlab. The indexing starts at 1.
So, I want to make sure I understand why the vector is as it is, before I (or anyone else) try to solve the issue. Otherwise you will have error upon error which will take time to answer.

추가 답변 (1개)

Ahmet Cecen
Ahmet Cecen 2014년 8월 17일
That means check sometimes don't have any 0 elements when you do
[indx,dum]=find(check==0);
Try instead:
if length(indx)>0
nodnum(j)=indx(1);
else
nodnum(j)=0;
end

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by