Error in Indexing & Matrix Dimension

1 回表示 (過去 30 日間)
RDG
RDG 2013 年 9 月 27 日
編集済み: RDG 2013 年 9 月 27 日
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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by