Error in Indexing & Matrix Dimension

2 次查看(过去 30 天)
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 个评论
Jan
Jan 2013-9-27
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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2013-9-27
编辑:Jan 2013-9-27
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by