Inner matrix dimensions must agree.

1 次查看(过去 30 天)
Jack
Jack 2014-10-28
回答: dpb 2014-10-28
Hi, having a little trouble making it multiply.
Sorry but I am fairly new to the software, and so have probably missed something very basic.
function move(n)
%column 1 is x, 2 is y, 3 is velocity, 4 is angle (radians)
P=10*rand(n,4);
plot(P(1:10,1),P(1:10,2),'o')
for t=0:0.01:20
P=P+(P(1:n,3)*(P(1:n,1)*cos(P(1:n,4))+P(1:n,2)*sin(P(1:n,4))));
plot(P(1:10,1),P(1:10,2),'o')
pause(0.5);
end
Any help would be great.

回答(2 个)

Ganesh Gaonkar
Ganesh Gaonkar 2014-10-28
From your question, It was not clear to me, what value of 'n' you are passing to this function. However, you can just put a break point in the line above the one where the error occurs to see if all arguments/variables are getting calculated with right dimensions.That way you can check the value of each variables in debug mode and locate the cause of the issue.

dpb
dpb 2014-10-28
P=P+(P(1:n,3)*(P(1:n,1)*...
'*' is matrix multiply in Matlab and P(1:n,N) is a column vector of size nx1. To multiply two it would have to be nx1 X 1xn or 1xn X nx1 depending on whether you intend the result to be n-by-n or 1-by-1.
Or, if you intend the result to be the element-wise product of the two vectors and the result to be nx1 then
doc times
for the "dot" operator.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by