MATLAB: Is fplot empty while ezplot works on imaginary inputs

Symbolic Math Toolbox

Plotting a function with "ezplot" works fine, but MATLAB Documentation recommends using "fplot" instead and "fplot" produces an empty plot.
>> syms x y(x)
>> sol=dsolve(diff(y,x)==y^2-1,y(0)==2,x)
>> ezplot(sol) %plots as expected
>> fplot(sol) %empty plot
Why is the "fplot" empty?

Best Answer

The reason why the plot is not showing up is due to the imaginary part of "sol". The "ezplot" function ignores the imaginary part and just plots the real part. This happens to be good in this case, but is not a good method for all scenarios. For this reason, the "fplot" function simply leaves out parts of a function plot that are not real.
In order to get the desired plot, simply grab the real part of "sol".
>> fplot(real(sol))