MATLAB: Do I get the error “Dimensions of arrays being concatenated are not consistent.”

matlab error

Can anybody help me why my code show me this error when i run it? i have attached my code.

Best Answer

This error is encountered when you try to vertically concatenate arrays that do not have compatible sizes. For example, to vertically concatenate two matrices A and B, they must have the same number of columns:
A = ones(2,3)
B = ones(5,3)
C = [A; B]
C is a matrix with 7 rows and 3 columns.
However, if B has 4 columns instead of 3, you will get the error. For example,
B = ones(5,4)
C = [A; B]