Error in Indexing & Matrix Dimension

1 visualización (últimos 30 días)
RDG
RDG el 27 de Sept. de 2013
Editada: RDG el 27 de Sept. de 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 comentario
Jan
Jan el 27 de Sept. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 27 de Sept. de 2013
Editada: Jan el 27 de Sept. de 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.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by