Index in position 1 is invalid. Array indices must be positive integers or logical values.

1 回表示 (過去 30 日間)
ACHALA SHAKYA
ACHALA SHAKYA 2019 年 6 月 19 日
コメント済み: dpb 2019 年 6 月 20 日
function findalph = impGradDes(M, P)
[n, m, d] = size(M);
%% Initializing the optimal weight vector
findalph = ones(d,1);
%% Optimization process
for i=1:d
for j=1:d
A(i,j) = sum(sum(M(:,:,i).*M(:,:,j)));
end
B(i,1) = sum(sum(P.*M(:,:,i)));
end
tau = 5;
iter = 150000;
gamma1 = 1/200000;
gamma2 = 1;
inv = (eye(d) + 2*tau*gamma1*A)^(-1);
for i = 1:iter
findalph = inv * (findalph+2*tau*max(-findalph,0)+2*tau*gamma1*B);
end
end
  4 件のコメント
ACHALA SHAKYA
ACHALA SHAKYA 2019 年 6 月 20 日
A(i,j) = sum(sum(M(:,:,i).*M(:,:,j)))
B(i,1) = sum(sum(P.*M(:,:,i)));
The above error is in these lines.
dpb
dpb 2019 年 6 月 20 日
Yeah, I missed seeing the LHS variable also being on RHS, Stephen...

サインインしてコメントする。

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 6 月 20 日
OK, when you have a problem that simple (in terms of figuring out what is going on) you do this:
dbstop if error
Then rerun the code, matlab will then stop at the offending line and you get a prompt at that line making it possible for you to inspect the variables to see what's going on. Presumably something strange is happening with either i or j, so you
can just check those variable and the M and P variables too.
HTH

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by