Why do I keep getting matrix dimensions must agree?
조회 수: 1 (최근 30일)
이전 댓글 표시
I keep getting this error and I can't figure out why. Here's my code
g= 9.81
v0=[5,10,15,20];
theta= [0, .17453293, .52359878, .78539816, 1.04719755,1.57079633];
tf=2*v0.*sin(theta)/g;
t=0:0.01:tf; hold all x=v0.*(theta).*t;
y=v0*sin(theta)*t-g*t.^2/2;
hold on plot(x,y)
Matrix dimensions must agree.
Error in BallTrajectory (line 7) tf=2*v0.*sin(theta)/g;
댓글 수: 0
채택된 답변
James Tursa
2018년 7월 10일
편집: James Tursa
2018년 7월 10일
>> size(v0)
ans =
1 4
>> size(theta)
ans =
1 6
So it is complaining about the v0 .* sin(theta) operation
댓글 수: 3
James Tursa
2018년 7월 10일
tf is a vector. What are you expecting to get with the t=0:0.01:tf ?
What is your ultimate goal here? To produce multiple plots with different values of tf?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!