How do you print an anonymous function properly in a figure title?
28 views (last 30 days)
Show older comments
Commented: KieranSQ on 11 Feb 2019
I am trying to print an anonymous function as part of a title for a plot. I would like it to look like a latex entry where but we get f(x)=@(x)x.^2 instead.
I have provided a MWE below;
title(sprintf('The Evolution of the Heat Equation with Source f(x)=%s', func2str(f)))
aara on 11 Feb 2019
You could do it by manipulating the equation of the function alone and then adding it to the remaining text:
eqn = func2str(f);%changes to a char array
eqn2 = eqn(5:end);%removes the '@(x) handle
eqn3 = replace(eqn2,'.','') %removes the . used for multiplication
placeholder1 = "The Evolution of the Heat Equation with Source $f(x)=" + string(eqn3+ "$")
Not sure if this works for all equations.
More Answers (0)
Find more on 2-D and 3-D 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!