function parameter includes h(=10). I want plot title to include the same h. how to do?
function G=graphit(X,Y,ye,h)
plot(X,Y,'-');
grid
title([ 'Approximate and Exact Solution @h= .', num2str(h)])
Thanks. MM
function parameter includes h(=10). I want plot title to include the same h. how to do?
function G=graphit(X,Y,ye,h)
plot(X,Y,'-');
grid
title([ 'Approximate and Exact Solution @h= .', num2str(h)])
Thanks. MM
You can use sprintf
to create a formatted string
title( sprintf( 'Approximate and Exact Solution. h = %.0f', h ) );
Despite 3 excellent answers given in less than 5 minutes, none of the suggested code would run properly. Basically, I got almost identical results as when I ran my original code.
It turns out that leading zeroes in a number for h such as 01 or 05 will cause the system to drop the zero. This was a problem for me since I wanted h values to be as they are .05, .025, .01. Further, the Matlab software seemed to become confused with a specified decimal point followed by a number with leading zeroes. The way around this was to pass the decimal point with the h value (.10,.05,.025,.01). See code below.
Input is
X,Y,xe,ye,.01
Working code:
function G=graphit(X,Y,xe,ye,h)
hold on;
plot(X,Y,'-'); plot(X,ye,'-.');
hold off
title([ 'Approximate and Exact Solution @h=', num2str(h)])
Expected and attained output: Approximate and Exact Solution @h=0.01
Voila! Thanks for those replies...