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

1 vue (au cours des 30 derniers jours)
Thomas
Thomas le 20 Juin 2016
Commenté : Thomas le 20 Juin 2016
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 commentaires
Torsten
Torsten le 20 Juin 2016
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 le 20 Juin 2016
Thanks Torsten, I'm always looking for ways to improve my coding!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by