Index exceeds matrix dimensions error "for my code"
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposta accettata
Star Strider
il 17 Gen 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 Commenti
Star Strider
il 17 Gen 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.
Più risposte (1)
AZ AI
il 17 Gen 2020
1 Commento
Star Strider
il 17 Gen 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.
Vedere anche
Categorie
Scopri di più su Modeling and Prediction in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!