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

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 20 Giu 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 il 20 Giu 2016
Thanks Torsten, I'm always looking for ways to improve my coding!

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by