简体   繁体   English

MATLAB:下标的分配维不匹配

[英]MATLAB: Subscripted assignment dimension mismatch

I do not understnad the reason why MATLAB display error when I type the following lines in the command line. 我不理解在命令行中键入以下行时MATLAB显示错误的原因。

k=2; 

c=[0 0 0 1 0 0 0 0;0 0 0 0 1 0 0 0];

temp1=[1 0;2 0;1 0;5 0;9 0;5 0;6 0;7 0];

s=c*temp1;

w(2,k)=s

Subscripted assignment dimension mismatch. 下标分配尺寸不匹配。

>> s

s =

     5     0
     9     0

where w(2,k) is nothing but a 2x2 matrix and assigned 2x2 matrix and it still display that error. 其中w(2,k)只是2x2矩阵和分配的2x2矩阵,它仍然显示该错误。 I would like to thank the person who ever out there can help better my understandings on this topic. 我要感谢能够帮助我更好地理解这一主题的人。

The error is that w(2,k) is a 1x1 matrix and you're trying to put s , a 2x2 matrix in it. 错误是w(2,k)1x1矩阵,而您试图将s2x2矩阵)放入其中。 When you're doing an assignment operation, ie = , both side of the equals sign have to have the exact same dimensions. 在执行赋值操作(即= ,等号的两边必须具有完全相同的尺寸。 If they don't then you get a dimension mismatch error. 如果它们不匹配,则会出现尺寸不匹配错误。

if w is a 2x2 as you say then w = s should work, or w(2,k) = s(2, k) should work too. 如果w如您所说是2x2 ,则w = s应该起作用,或者w(2,k) = s(2, k)应该起作用。 What exactly are you trying to achieve? 您到底想达到什么目的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM