MATLAB: Index exceeds matrix dimensions error “for the code”

databaseerrormachine learningMATLABstatisticsStatistics and Machine Learning Toolbox

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 1200×6 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?

Best Answer

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.