Inner matrix dimensions must agree.
    조회 수: 7 (최근 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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!