3 Errors involving linespace and multiplication symbol

Trying to code a projectiles motion from start to when it hits y=0. All the numbers/data is in. Part of the assignment is to create user-defined inputs as you'll see in the code. Problem i'm having is without any of the user inputs, the code runs fine. Once I insert user defined inputs, I get 3 errors.
The errors are:
Error using .*
Matrix dimensions must agree.
Error in linspace (line 30)
y = d1 + (0:n1).*(d2 - d1)/n1;
Error in DummyCode (line 22)
t = linspace(0, tend, 1000);
I made a dummy file that's the exact same code as my assignment just without my comments,has the same errors, here it is:
a = input('45');
b = input('0');
c = input('0');
d = input('90');
Angle_deg = d;
Angle_rad = Angle_deg * pi/180;
V0 = a;
Vox = V0 * cos(Angle_rad);
Voy = V0 * sin(Angle_rad);
Y0 = c;
X0 = b;
g = -9.81;
ax = 0;
ay = g;
tend = (-Voy - sqrt(Voy^2 - 4.*(.5.*ay).*Y0))/(2 .*((.5).*ay));
size(tend);
t = linspace(0, tend, 1000);
x = X0 + V0*t + .5 * ax * t.^2;
y = Y0 + V0*t + .5 * ay * t.^2;
plot(x,y)

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 21일

0 개 추천

I do not get any error when I run that code and answer to the input prompts with the value printed out in the prompt.
However I suspect that the actual input mechanism you are using is something like inputdlg(), which does not return numbers: it returns a cell array of character vectors.

댓글 수: 1

Yeah I ended up figuring it out, in my inputs at the top I entered values where I should of put in questions/text to the user like "Insert velocity", that ended up fixing it and getting it running. Thanks for the answer though.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

Moe
2017년 9월 21일

댓글:

Moe
2017년 9월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by