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

4 views (last 30 days)
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
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);
if MaxDist(j) < maxval(j)
MaxDist(j) = maxval(j);
for k=1:32
Radius(k,:) = exp(log(MinDist) + k*(log(MaxDist) - log(MinDist))/32);

Answers (1)

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 Comment
ryunosuke tazawa
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;

Sign in to comment.


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!