Clear Filters
Clear Filters

What causes difference between ezplot and fplot for the same function plotted below?

10 views (last 30 days)
Trying to understand difference between ezplot and fplot? When script below is graphed for ezplot around 0.2 sec there appear to be 2 changes in slope of line. Howeve, for fplot around 0.2 sec there is only 1 change in slope of the line (which is the desired result)
%% Code
Fo = 3000; %N
to = 0.2; %s
syms t
F = (Fo/to)*(t*heaviside(t)-(t)*heaviside(t-to)+ to*heaviside(t-to)-to* heaviside(t-5*to) );
%%%%%%%%%%%%%
figure (1)
ezplot(F, [0, 10*to])
title('From ezPlot')
xlabel('time [s]')
ylabel('Force [N]')
%%%%%%%%%%
figure(2)
fplot(F, [0, 10*to])
title('From fplot')
xlabel('time [s]')
ylabel('Force [N]')

Accepted Answer

lokender Rawat
lokender Rawat on 4 Apr 2018
ezplot(f) plots the expression f(x) over the default domain -2π < x < 2π, where f(x) is an explicit function of only x.
Where as, fplot(f) plots the curve defined by the function y = f(x) over the default interval [-5 5] for x.
We can plot the curve over some specified interval as well. The curve that is produced is same for both the functions. But ezplot is not recommended as it behaves differently under different environments and fplot is used instead.
To get the correct alignment with ezplot, you can use the below command right after the ezplot function command as below to adjust the curve:
ezplot(F, [0, 10*to]);
ylim([0,3000])
ylims sets the y-axis limits for the current axes or chart. Both the figures now will have same curve with corresponding values aligned.

More Answers (1)

ahmad amer
ahmad amer on 19 Dec 2018
ezplot(F, [0, 10*to]);
ylim([0,3000])

Community Treasure Hunt

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

Start Hunting!