Error using sym/cat>checkDimensions CAT arguments dimensions not consistent.
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
I have the following code (there is a space before the minus sign in the first equation):
eqns = [x -y==0;
        x+y==0]
This generates the following series of messages:
    Error using sym/cat>checkDimensions CAT arguments dimensions not consistent.
    Error in sym/cat>catMany (line 33) [resz, ranges] = checkDimensions(sz,dim);
    Error in sym/cat (line 25)  ySym = catMany(dim, args);
    Error in sym/vertcat (line 19)  ySym = cat(1,args{:});
If I delete the space before the minus sign it works fine:
eqns = [x-y==0;
        x+y==0]
Or a space behind the minus sign it also works fine:
eqns = [x - y==0;
        x+y==0]
Why is it not allowed to use a space before the minus sign?
0 个评论
回答(1 个)
  Bhanu Prakash
    
 2023-3-15
        
      编辑:Bhanu Prakash
    
 2023-3-15
  
      Hi Jos, 
As per my understanding, you are trying to initialize a matrix containing linear equations but are facing some errors, when you tried to initialize them differently. 
In the first case, where there is a space before the minus sign, both "x" and "-y==0" are identified as separate elements by the compiler. So, the compiler tries to create a row matrix using those two elements. But the second row has only one term i.e., "x+y==0", making the dimensions of the matrix inconsistent. This is leading to the error saying, "CAT arguments dimensions not consistent". 
Please have a look at the code below, for your reference: 
eqns=[x -y==0] 
The output of the above code is mentioned below, which indicates a row matrix:  
eqns = 
[x, -y == 0] 
In all other cases, the compiler considers "x-y==0" as a single element, thereby creating a column matrix having the elements "x-y==0" and "x+y==0". 
You can access the documentaion for “Matrices and arrays” here: 
Hope this answer helps you. 
Thanks, 
Bhanu Prakash. 
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!