Can I plot with a function?
1 view (last 30 days)
Show older comments
Anastasia Zistatsis
on 25 Mar 2021
Answered: Walter Roberson
on 25 Mar 2021
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 Comments
Walter Roberson
on 25 Mar 2021
What is the code for your derivf function? It does not appear to be a Mathworks function.
Accepted Answer
Walter Roberson
on 25 Mar 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!