28.12.2012 Views

Figure Properties - SERC

Figure Properties - SERC

Figure Properties - SERC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2func2str<br />

Purpose Construct a function name string from a function handle<br />

Syntax s = func2str(fhandle)<br />

func2str<br />

Description func2str(fhandle) constructs a string s that holds the name of the function<br />

to which the function handle fhandle belongs.<br />

When you need to perform a string operation, such as compare or display, on a<br />

function handle, you can use func2str to construct a string bearing the<br />

function name.<br />

The func2str command does not operate on nonscalar function handles.<br />

Passing a nonscalar function handle to func2str results in an error.<br />

Examples Example 1<br />

Convert a sin function handle to a string:<br />

fhandle = @sin;<br />

func2str(fhandle)<br />

ans =<br />

sin<br />

Example 2<br />

The catcherr function shown here accepts function handle and data<br />

arguments and attempts to evaluate the function through its handle. If the<br />

function fails to execute, catcherr uses sprintf to display an error message<br />

giving the name of the failing function. The function name must be a string for<br />

sprintf to display it. The code derives the function name from the function<br />

handle using func2str:<br />

function catcherr(func, data)<br />

try<br />

ans = func(data);<br />

disp('Answer is:');<br />

ans<br />

catch<br />

disp(sprintf('Error executing function ''%s''\n', ...<br />

func2str(func)))<br />

end<br />

2-911

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!