1
votes

I am trying to create a 3D matrix in MATLAB. I have followed this example. My code is as such:

A1=zeros(50,2,10);
A1 = [1 2; 2 3; 3 11; 11 12; 11 9; 9 10; 9 7; 7 8; 7 5; 5 6; 5 4; 4 3];

A1(:,:,2) = [1 3; 3 2; 3 4; 3 5; 5 6; 6 7; 6 8; 6 9; 9 10; 10 11; 11 12; 12 13; 11 17; 17 16; 16 14; 14 15; 14 12; 16 18; 18 27; 18 19; 19 20; 20 21; 27 21; 27 26; 21 22; 26 25; 25 24; 24 22; 22 23]

The error I am getting is: Subscripted assignment dimension mismatch.
Where am I going wrong can someone tell me?

1
Could you explain the expected output? You are not assigning enough elements for a [50 2 10] matrix. - Daniel

1 Answers

0
votes

What you do with A1(:,:,2) is that you want to insert a 50x2 matrix to the second position of a 50x2x10 hypermatrix. But the matrix of the right hand side has not not enough rows for it (29, instead of 50).