Inner matrix dimensions must agree.
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
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.
0 件のコメント
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.
0 件のコメント
参考
カテゴリ
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!