Hi I'm trying to execute a program but I keep getting this error:
"Attempted to access indx(1); index out of bounds because numel(indx)=0"
I understand what it means, but I'm not able to fixe it, I need some help.
Here is the code with the error:
[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
Thank you guys
My assessment: It found no values where check was equal to zero, so there was no value for 'indx'.
I don't have everything I need to double check this, but make sure that
really is returning a result.
Hamid - What is the data type of the numbers in Dof and Edof - integers or floats? If floats, then you will not be able to use find(check==0) and will have to use some sort of tolerance around the numbers to see which are close enough to zero i.e.
check = [1 1.2 0.00000003 3.2 -0.00000004 4 12 55]'; tol = 0.000001; [rowIdcs,colIdcs]=find(abs(check)<tol);
And then, check to see if anything is returned before accessing rowIdcs
if ~iesmpty(rowIdcs) nodnum(j)= rowIdcs(1); end
(I renamed indx and dum to rowIdcs and colIdcs because that is what the two output parameters refer to - the row indices and the column indices of the elements of check that satisfy the criteria.)
In the above example, since check is a column vector (due to the transpose '), then rowIdcs will have the indices of the rows of check that satisfy the criteria
and those values are
But you need to be careful. If check happens to be a row vector, then you need to use colIdcs to access those elements in check. And...if check happens to be a matrix, then you will need to use both vectors, rowIdcs and colIdcs, to get the correct value from check.
Play games and win prizes!Learn more