Can I plot with a function?
조회 수: 4 (최근 30일)
이전 댓글 표시
I need to plot the velocity function versus time, but when I do, nothing shows up on the graph. Any ideas?
t = [0,0.52,1.04,1.75,2.37,3.25,3.83];
x = [153,185,208,249,261,271,273];
%plot approximate velocity over [0,3.83]
%part i, create x(t) then find derivative
i = interp1(x,t,0,'spline');
f = @(xx)interp1(t,x,xx,'spline');
velocity = derivf(f,0,0.0001); %88.2979
plot(velocity,[0 3.83],'g')
xlabel('time(s)')
ylabel('position(m)')
hold on
댓글 수: 2
Walter Roberson
2021년 3월 25일
What is the code for your derivf function? It does not appear to be a Mathworks function.
채택된 답변
Walter Roberson
2021년 3월 25일
velocity = derivf(f,0,0.0001); %88.2979
that passes the scalar with value 0 as the x to derivf
Df=4/3*Df2-1/3*Df1;
That calculates an output the same size as x .
You are calling it with x being the scalar 0. So velocity will be a scalar.
plot(velocity,[0 3.83],'g')
velocity is a scalar. When you plot with a scalar x, you get dots at each of the y values... but you do not have markers turned on so you will not even see the dots. You could
plot(velocity,[0 3.83],'*g')
to see the points (velocity,0) and (velocity, 3.83)
I suspect you were thinking that you were asking to plot velocity over a range of x values from 0 to 3.83, but you are not doing so. Automatic plotting like that needs fplot() instead of plot(), and it needs the first parameter to be a function handle or a symbolic expression or a symbolic function.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!