Programmers learn & share
65 views

Recently, I have started exploring MATLAB from a beginner’s level, and I came to know that this software has got some fantastic features to build any type of code. Still, there are specific rules that must be followed first, for matrix operations. Many times, we work on building an efficient code, but it does not run. After spending quite a time debugging, we come to know that the error occurred is so fundamental in a level like either about case sensitivity or we forget to use the same dimensions in an equation.

One of the basic error in MATLAB is “Assignment has more non-singleton rhs dimensions than non-singleton subscripts”. As we know, there must be a satisfaction in an equality, this means an equation should satisfy its properties. Same rule will apply in MATLAB, to solve the equation of matrices or equating a variable.

To discuss in detail, how to overcome the said error, we have to explain an example. Let us take two matrices A and B having a dimensions of 3 by 3 and 3 by 2 respectively, given as

A = [0  2  5;4  5  6;6  7  8];

B = [7  9;2  4;0  1];

We are going to write these matrices in terms of other variable C(1) which is not compatible to an operation of matrix A and B, taking the matrix multiplication, like,

C(1) = A*B;

From the above equation, the left hand side is not compatible with right hand side, because the assigned variable is not correct. This error is shown as above as title of this article in MATLAB versions R2017b and all the previous ones, throws this error because the size of the left-hand side is 1-by-1, but the size of the right-hand side of the product of two variables is 3 by 2. This error is modified in the MATLAB versions 2018a and all the latest ones, the new error that replaces the previous one is unable to perform assignment because the indices on the left side are not compatible with the size of right side.

The above error will be removed, when you use the correct dimension on both sides, and can be written as

C(3,2) = A*B;

This equation gives no error, because C(3,2) has three rows and two columns, which is equal to the dimension of right hand side. Let us discuss rhs in detail, rhs is also used to find out the dimension or values on right hand side of an equation or a table, if an equation or a table is dimensionally correct, then the i-th element corresponds to the left side of that equation or a table as well.

  •  rhs(f) returns the right hand side of function (f).

The call rhs(f) is equivalent to the direct call op(f, 2), of the operand function op, if f is not a table. If t is a table, the call rhs(t) returns the list of values of the table (right hand side).

posted Mar 31 in other by (100 points)   | 65 views
2,218 questions
2,683 answers
59 comments
241 users