www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AnonymousFunctionsWithoutAFileExample.m
%% Anonymous Functions Without a File % Anonymous functions allow you to define a function without creating a % program file, as long as the function consists of a single statement. A % common application of anonymous functions is to define a mathematical % expression, and then evaluate that expression over a range of values % using a MATLAB(R) _function function_, i.e., a function that accepts a function handle as an input. %% % For example, this statement creates a function handle named |s| for an anonymous function: % Copyright 2015 The MathWorks, Inc. s = @(x) sin(1./x); %% % This function has a single input, |x| . The |@| operator creates the function handle. % % You can use the function handle to evaluate the function for particular values, such as y = s(pi) %% % Or, you can pass the function handle to a function that evaluates over a range of values, such as |fplot|: range = [0.01,0.1]; fplot(s,range)