"Assignment has more non-singleton rhs dimensions than non-singleton subscripts"

1 回表示 (過去 30 日間)
Thomas
Thomas 2016 年 6 月 20 日
コメント済み: Thomas 2016 年 6 月 20 日
Hey all, having the problem "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" as stated above.
Firstly, I know what this problem means and where the error is occuring, I just cannot figure out a solution for it.
My code is as followed:
a0 = [0 0 0];
b0 = a0/3 .* [1 1 1];
a1 = a0/2 .* [0 1 1];
a2 = a0/2 .* [1 0 1];
a3 = a0/2 .* [1 1 0];
In = n .*a1 + m .*a2 + l .*a3;
P = n .*a1 + n .*a2 + l .*a3 + b0;
for n = 1:5
for m = 1:5
for l = 1:5
In(n+1,m+1,l+1,:) = a0;
P(n+1,m+1,l+1,:) = a0 + b0;
end
end
end
The error occurs in:
In(n+1,m+1,l+1,:) = a0;
  3 件のコメント
Torsten
Torsten 2016 年 6 月 20 日
Note that the lines
In = n .*a1 + m .*a2 + l .*a3;
P = n .*a1 + n .*a2 + l .*a3 + b0;
are superfluos and that you can get the same result for In and P if you just initialize them to zero:
In = zeros(6,6,6,3);
P = zeros(6,6,6,3);
Best wishes
Torsten.
Thomas
Thomas 2016 年 6 月 20 日
Thanks Torsten, I'm always looking for ways to improve my coding!

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

回答 (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