Effacer les filtres
Effacer les filtres

Error in Indexing & Matrix Dimension

1 vue (au cours des 30 derniers jours)
RDG
RDG le 27 Sep 2013
Modifié(e) : RDG le 27 Sep 2013
I have the following code excerpt and I've been debugging for days. When I tried with a smaller scale (5 variables), it's alright but when I tried with 95, it returned an error,
"Index exceeds matrix dimensions.
Error in Workshop (line 307) outoo{i}(i00{i} == jj,2:4) = availmat{i}(t(1:ba{i}(jj)),1:3);"
load('duplicatematrices');
load('availmat');
for i=1:95
[ba{i},i00{i}] = histc(duplicatematrices{i}(:,2),unique(duplicatematrices{i}(:,2)));
outoo = duplicatematrices;
for jj = 1:numel(ba{i})
t = find(availmat{i}(:,1) == jj);
outoo{i}(i00{i} == jj,2:4) = availmat{i}(t(1:ba{i}(jj)),1:3);
end
end
Can someone please help me?
  1 commentaire
Jan
Jan le 27 Sep 2013
Please add a complete copy of the error message by editing the question. Then we do not have to guess the exact message and the location of the error.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 27 Sep 2013
Modifié(e) : Jan le 27 Sep 2013
As usual for this error message (or at least what I guess the error message is): The debugger help to find the problem:
dbstop if error
Then run the code again until it stops, when the problem occurs. Then inspect the dimensions of the locally used variables. Perhaps duplicatematrices has less than 95 elements, or the contents of duplicatematrices{i} has less than 2 columns, or availmat has less than 95 elements? Are you sure that t has the required number of ba{i}(jj) elements?
It is easier, when you try to find answers for these questions by your own.
What you will find out in less than a minute:
For i==11, j==2, t has 14 elements only, but ba{11}(2) is 15. Therefore t(1:ba{i}(jj)) cannot work.
I cannot suggest an improvement, because all I see is the not working code, while I cannot guess its intention. It is like "I have a+b=17, but I want another result" - impossible in theory to guess what the user needs.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by