If I have a simple matrix
A = [1 3 ; 4 3 ; 6 12]
And then go
A(:,3) = (A(:,1)+A(:,2))
then every element in column 3 will contain the sum of its counterparts in columns 1 and 2.
However, when I go
A(:,3) = (A(:,1)/A(:,2))
I get an error message Subscripted assignment dimension mismatch. Google searches did not reveal an enlightening explanation of this error message. Can anyone here help?
A(:,3) = (A(:,1)/A(:,2))is actually doing a matrix division.
I’m guessing you want to the divide corresponding elements of the vectors. In this case you need to add a dot to the division. So the code you want would read…
A(:,3) = (A(:,1)./A(:,2))See http://www.mathworks.com/help/matlab/ref/arithmeticoperators.html for a pretty good explanation.