Index exceeds matrix dimensions error "for my code"

1 view (last 30 days)
I have a dataset with 1200 rows and 6 coulmns. The sixth coulmn is the dependent variable which I need to remove for the porpuse of my code. I have tried this code with many diffrent datsets and it works except this dataset and few others. I got the message "Index exceeds matrix dimensions".
names = {'M'};
normalisation = 1; % normalisation to unit variance
condNumber = 10;
nN = length(names);
dimens = zeros(nN, 4);
for k = 1:nN
% Display database name
fprintf('\n%s',names{k});
% Load database
% I imported my data using imported icon
X(:,6) = [] % remove a dependent variable
% normalise if necessary
if normalisation == 1
X = zscore(X);
elseif normalisation == 2
mi = min(X);
ma = max(X);
X = bsxfun(@rdivide, bsxfun(@minus, X, mi), (ma - mi));
end
% Calculate results
e = svd(X) .^ 2;
e = sort(e,'descend');
dimens(k, 1) = sum(e >= mean(e));
dimens(k, 2) = brokenStick(e);
ind = find(e < (e(1) / condNumber));
dimens(k, 3) = ind(1) - 1;
[~, dimens(k, 4)] = SeparabilityAnalysis(X);
end
end
When I mported the data, I used numeric matrix and olny loaded 1200x6 matrix and it is ok.
The peoblem with code "Index exceeds matrix dimensions", but I do not wht it works with other same datset but not with this.
Bear in mind I used others datset from the same website and large rows and columns and the code works fine.
friedman datset
Can anyone guide me with this error please?

Accepted Answer

Star Strider
Star Strider on 17 Jan 2020
It is unfortunate that we do not get the opportunity to see what ‘X’ is for the various files, nor anything else about them.
If you always (and only) want to remove the last column, then:
X = X(:,1:end-1);
would work, and you can completely remove this line:
X(:,6) = [] % remove a dependent variable
that may be throwing the error.
Alternatively:
X = X(:,1:5);
might be appropriate.
We have no way of testing that to determine what may be best.
  20 Comments
AZ AI
AZ AI on 17 Jan 2020
The "Fractal" dimenion has another code ans is ok. The question is only for PCA-K, PCA-BS , PCA-CN , and SepD dimension.
With all datasets, I import the data and remove the dependet variable.
I can read the data file, but with some datasets the code is running (gives me number of dimesnion value for PCA-K, PCA-BS , PCA-CN, SepD) and with some others as "friedman" is not working and giving me an error message "Index exceeds matrix dimensions".
Star Strider
Star Strider on 17 Jan 2020
I can help you read the data files and extract the columns you want from the imported matrices.
It would appear that you may be ‘hard-coding’ something about the matrices, rather than adapting your code to the dimensions of the individual matrices. I cannot help you with the fractal dimension and related code because I have no idea what you are doing.

Sign in to comment.

More Answers (1)

AZ AI
AZ AI on 17 Jan 2020
Thank you so much and I will try to see what is the problem.
  1 Comment
Star Strider
Star Strider on 17 Jan 2020
As always, my pleasure!
I will help as much as I can, however I will need a clearer description of what you want to do in order to help most effectively. Just now, I have no idea.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!