1
votes

I do not understnad the reason why MATLAB display error when I type the following lines in the command line.

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. I would like to thank the person who ever out there can help better my understandings on this topic.

1
It might help if you could explain a bit more about what you want to achieve. Do you want to fill w with the contents of s? Also, what is w? You didn't define it in your example code. - Marius

1 Answers

1
votes

The error is that w(2,k) is a 1x1 matrix and you're trying to put s, a 2x2 matrix in it. When you're doing an assignment operation, i.e. =, 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. What exactly are you trying to achieve?