Error with a function

조회 수: 2 (최근 30일)
Corey Bullard
Corey Bullard 2012년 4월 25일
I have three errors:
??? Subscript indices must either be real positive integers or logicals.
Error in ==> velocity at 3
v = -r*angular_velocity(sin(angular_velocity*t)+((r)/(2*l_value))...
Error in ==> HW10 at 19
x_dot = velocity( r, angular_velocity, t, l_value );
This is part of my script:
for l_value = (r + .5):((15-(r + .5))/5):15;
x_dot = velocity( r, angular_velocity, t, l_value );
v(m) = x_dot;
m = m + 1;
plot(x_dot,l_value);
end
The error seems to be with the function. Here is the function velocity:
function [ v ] = velocity( r, angular_velocity, t, l_value )
%Calculate velocity
v = -r*angular_velocity(sin(angular_velocity*t)+((r)/(2*l_value))...
*((sin(2*angular_velocity*t))/(sqrt(1-((r/l_value)*(...
sin(angular_velocity*t)))^2))));
end
Any help or tips will be greatly appreciated!

채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 25일
angular_velocity*t implies that angular_velocity is a numeric quantity (scalar, vector, array). sin() of that would also be a numeric quantity, but very likely not positive-integer-valued. You then use angular_velocity indexed at that sin() expression, so that is likely to fail.
  댓글 수: 2
Kevin Holst
Kevin Holst 2012년 4월 25일
translation:
Turn this:
v = -r*angular_velocity(sin(angular_velocity*t)+((r)/(2*l_value))...
into this:
v = -r*angular_velocity*(sin(angular_velocity*t)+((r)/(2*l_value))...
;)
Corey Bullard
Corey Bullard 2012년 4월 25일
Thanks a lot, that fixed it. I'm not sure how I missed that, I will certainly be more careful in the future.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by