MATLAB POLYSPACE RELEASE NOTES User Manual Page 166

  • Download
  • Add to my manuals
  • Print
  • Page
    / 240
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 165
4 Programming
s = ['August' int2str(d) '.dat'];
load(s)
% Code to proc ess the contents of the d-th file
end
The eval Function
The eval function works with text v ariables to implement a powerful text
macro facility. The expression or statement
eval(s)
uses the MATLAB interpreter to e valuate the expre ssion or execute the
statement contained in the text string
s.
Theexampleoftheprevioussectioncouldalsobedonewiththefollowing
code, al though this would b e somewhat less efficient be c au se it in volves the
full interpreter, not just a function call:
ford=1:31
s = ['load August' int2str(d) '.dat'];
eval(s)
% Process the contents of the d-th file
end
Function Handles
You can create a handle to any MATLAB function and then use that handle
as a means of referencing the function. A function handle is typically passed
in an argum ent list to other functions, w hich can then execute, or evaluate,
the function using the handle.
Construct a function handle in MATLAB using the at sign,
@,beforethe
function name. The following example creates a function handle for the
sin
function and assigns it to the variable fhandle:
fhandle = @sin;
You can call a function by means of its handle in the same way that you would
call the function using its name. The syntax is
fhandle(arg1, arg2, ...);
4-28
Page view 165
1 2 ... 161 162 163 164 165 166 167 168 169 170 171 ... 239 240

Comments to this Manuals

No comments