Script AnonymF1.m
Download Script AnonymF1.m
%----------------------------------------------------------
%A script using an anonymous function M-file:AnonymF1.m
%----------------------------------------------------------
%%
%anonymous function
%that converts degrees into radians
conv=@(deg)(pi/180)*(deg);
%the array deg 1x4 is defined
deg=0:30:90;
%the function_handle conv is used for conversion
radian=conv(deg);
%properties of conv and radian are ascertained
%through the final command WHOS
%----------------------------------------------------------
%%
%the anonymous function is defined
h=@(x)sin(x);
%input argument x is defined into the function_handle h
y1=h(-2*pi:0.1:2*pi);
plot(-2*pi:0.1:2*pi,y1),title('sin')
figure
%----------------------------------------------------------
%%
%EZPLOT can have a function_handle as argument
%whereas PLOT must have as arguments arrays of class double
%conversion to double from function_handle is not possible
ezplot(@cos)
%plot(@cos) would return an error
%----------------------------------------------------------
%%
%the anonymous function uses cell array
%to calculate a polynomial of degree two
%each element of the cell is an anonymous function
A={@(a,x)a*x^2,@(b,x)b*x,@(c)c};
%when the function is called, the values of corresponding
%input arguments are defined for each element of the cell
y2=A{1}(-2,10)+A{2}(3.5,10)+A{3}(2.75);
whos
%----------------------------------------------------------
Back