# Index exceeds the number of array elements. Index must not exceed 0.

4 views (last 30 days)
ryunosuke tazawa on 26 Feb 2022
Commented: ryunosuke tazawa on 26 Feb 2022
Now I make code which estimate Correlation dimension．But ,error happed
「 Index exceeds the number of array elements. Index must not exceed 0.
error: Distance (column 27) if MinDist(j) > minval(j)
error: CorrDim (column 35) [Radius] = Distance(xnew, Nopoints)」
A function named 'Distance' is affecting the error. How to fix it? Which matrix index do I need to consider?
X = x2; % load data
MaxEmDim = 3;
TimeDelay = 2;
%% Reconstraction by timedelay embdding
%% Portrait = Reconstraction trajectory, NoPoints = Nomber of points each dimension, MaxPosEmDim
[Portrait_X, Nopoints_X, MaxPosEmDim_X] =Trajectory(X, MaxEmDim, TimeDelay); %
Unrecognized function or variable 'Trajectory'.
%% draw atracttor
figure(1)
plot(Portrait_X(:,3),Portrait_X(:,1),'bo','MarkerFaceColor','b','MarkerSize',5)
grid on
%% Calculation of correlation dimension
xnew = Portrait_X; % n×3 matrix
% number opf valid points in xnew matrix
Nopoints = [size(xnew)*[1;0] size(xnew)*[1;0] size(xnew)*[1;0]];
% caluculates 32 equi-spaced bins on a logarithmic scale
[Radius] = Distance(xnew, Nopoints); %% error happend●●
%% function caluculates distances point to point
% Radius is the matrix{32,MaxEmDim} in which the difference between the
% maximum and minimum distances from one point to any other, is diveded
% into 32 logarithmically equal intervals (for any dimensions)
% Portrait is trajectory data, Nopoints is vector in which the number of
% valid points for each dimensions
function [Radius] = Distance(Portrait, NoPoints)
MaxEmDim = size(Portrait) *[0;1];
NoPointsEnd = [NoPoints 1];
MinDist = ones(1, MaxEmDim)*1e20;
MaxDist = zeros(1, MaxEmDim);
Radius = zeros(32, MaxEmDim);
for EmDim = 1:MaxEmDim
minval = zeros(1, EmDim);
minloc = zeros(1, EmDim);
maxval = zeros(1, EmDim);
maxloc = zeros(1, EmDim);
for i=NoPointsEnd(EmDim):-1:NoPointsEnd(EmDim+1)+1
Distances = DistVectPoint(Portrait(1:1-1,1:EmDim), Portrait(i, 1:EmDim));
DistanceNoZero = ElimZero(Distances, 1e-10);
[minval, mincol] = min(DistanceNoZero,[],1);
[maxval, maxloc] = max(Distances, [], 1);
for j=1:EmDim
if MinDist(j) > minval(j) %%●● here is involved error
MinDist(j) = minval(j);
end
if MaxDist(j) < maxval(j)
MaxDist(j) = maxval(j);
end
end
end
end
for k=1:32
Radius(k,:) = exp(log(MinDist) + k*(log(MaxDist) - log(MinDist))/32);
end
end

Jan on 26 Feb 2022
This is strange:
MaxEmDim = size(Portrait) *[0;1];
Nopoints = [size(xnew)*[1;0] size(xnew)*[1;0] size(xnew)*[1;0]]
Use size(X, 1) and size(X, 2) instead.
The line:
if MinDist(j) > minval(j)
fails, if minval or MinDist is empty. You have to catch this exception explicitly.
##### 1 CommentShowHide None
ryunosuke tazawa on 26 Feb 2022
First ,Nopoints is the score in each dimension and has been changed as follows.
Nopoints = [size(X,1) size(X,2) size(X,3)] %[484 482 480]
How should I explicitly catch the exception?
Should I change the value of the following value (1e20)?
MinDist = ones(1, MaxEmDim)*1e20;