-1
BE2A = 2*0.3048;
BE2B = 2*0.3048;
BETA = 0;

for i = 1:50

        for j = 1:i

            for k = 1:(i+1-j)

                % 1st quadrant
                BEXC(i,j,k,1) = i*0+j*0+(0.5+(k-1))*BE2A*cos(BETA/180*pi);
                BEYC(i,j,k,1) = i*0+j*0+(0.5+(k-1))*BE2A*sin(BETA/180*pi);
                BEZC(i,j,k,1) = i*0+(0.5+(j-1))*BE2B+k*0;
                BE2A(i,j,k,1) = BE2A+i*0+j*0+k*0;
                BE2B(i,j,k,1) = BE2B+i*0+j*0+k*0;
                ANGLE(i,j,k,1) = BETA+i*0+j*0+k*0;

                % 2nd quadrant
                BEXC(i,j,k,2) = i*0+j*0-(0.5+(k-1))*BE2A*cos(BETA/180*pi);
                BEYC(i,j,k,2) = i*0+j*0-(0.5+(k-1))*BE2A*sin(BETA/180*pi);
                BEZC(i,j,k,2) = i*0+(0.5+(j-1))*BE2B+k*0;         
                BE2A(i,j,k,2) = BE2A+i*0+j*0+k*0;
                BE2B(i,j,k,2) = BE2B+i*0+j*0+k*0;
                ANGLE(i,j,k,2) = BETA+i*0+j*0+k*0; 

            end

        end

    end

When I run this code, it appears that: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts". The errors start from the line

  • "BEXC(i,j,k,1) = i*0+j*0+(0.5+(k-1))*BE2A*cos(BETA/180*pi)"
Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
Jeremy_Tamu
  • 725
  • 1
  • 8
  • 21
  • 4
    The error message is pretty self-explanatory. `BEXC(i,j,k,1)` is one index and `i*0+j*0+(0.5+(k-1))*BE2A*cos(BETA/180*pi)` returns more than one number. – sco1 Apr 17 '16 at 23:33

2 Answers2

1

Let's go through this:

  1. I assume BETA changes, but you have left it out for clarity. If not, BETA is always 0, thus you can substitute cos(BETA/180*pi) and sin(BETA/180*pi) with 1 and 0 respectively.

    a. Check out cosd() and sind()

  2. You multiply a lot of terms by zero. Skip those for clarity.

And then over to your problem. In the following two lines, you are assigning the value BE2A to both BE2A(i,j,k,1) and BE2A(i,j,k,2). By doing this, you are creating a matrix BE2A with size [i, j, k, 2] (note the 2).

BE2A(i,j,k,1) = BE2A+i*0+j*0+k*0;
BE2A(i,j,k,2) = BE2A+i*0+j*0+k*0;

In the next iteration, k = 2, you have:

BEXC(i,j,k,1) = i*0+j*0+(0.5+(k-1))*BE2A*cos(BETA/180*pi);

Now, BE2A is matrix with size: [1, 1, 1, 2]. You are multiplying this term by a bunch of scalars, thus ending up with a matrix, not a single number. The index BEXC(i,j,k,1) is obviously a single number, this you have a mismatch.

I'm assuming there's a lot more going on in this loop. If this is all there is, then there are a lot of ways to improve it:

Community
  • 1
  • 1
Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
1
BE2A0 = 2*0.3048;
BE2B0 = 2*0.3048;
BETA0 = 0;

for i = 1:50

        for j = 1:i

            for k = 1:(i+1-j)

                % 1st quadrant
                BEXC(i,j,k,1) = i*0+j*0+(0.5+(k-1))*BE2A0*cos(BETA0/180*pi);
                BEYC(i,j,k,1) = i*0+j*0+(0.5+(k-1))*BE2A0*sin(BETA0/180*pi);
                BEZC(i,j,k,1) = i*0+(0.5+(j-1))*BE2B0+k*0;
                BE2A(i,j,k,1) = BE2A0+i*0+j*0+k*0;
                BE2B(i,j,k,1) = BE2B0+i*0+j*0+k*0;
                ANGLE(i,j,k,1) = BETA0+i*0+j*0+k*0;

                % 2nd quadrant
                BEXC(i,j,k,2) = i*0+j*0-(0.5+(k-1))*BE2A0*cos(BETA0/180*pi);
                BEYC(i,j,k,2) = i*0+j*0-(0.5+(k-1))*BE2A0*sin(BETA0/180*pi);
                BEZC(i,j,k,2) = i*0+(0.5+(j-1))*BE2B0+k*0;         
                BE2A(i,j,k,2) = BE2A0+i*0+j*0+k*0;
                BE2B(i,j,k,2) = BE2B0+i*0+j*0+k*0;
                ANGLE(i,j,k,2) = BETA0+i*0+j*0+k*0; 

            end

      end

end

Please change BE2A as BE2A0; BE2B as BE2B0;BETA as BETA0.