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

1 visualización (últimos 30 días)
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 comentarios
Torsten
Torsten el 20 de Jun. de 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 el 20 de Jun. de 2016
Thanks Torsten, I'm always looking for ways to improve my coding!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by