how to use function handle

조회 수: 1 (최근 30일)
googo
googo 2013년 6월 19일
Hello,
I want to write a function code that draw a funcion based on the user input.
function plotFunc(f,x_min,x_max)
f is a function handle.
for example I want to draw x^3 from 1 to -1... how can I defin it in the function?

답변 (2개)

Andrew Newell
Andrew Newell 2013년 6월 19일
Use ezplot.

Rhys
Rhys 2013년 6월 19일
편집: Rhys 2013년 6월 20일
Hi!
to define your function you can use the inline() command and then to plot you can use the fplot() command. Your code may look something like this.
f = inline('x^3') % This creates an inline function
fplot(f, [-1, 1]) % This will plot the inline function f from the limits %set in the second input. Then you can edit the plot area anyway that you %would like (add axis labels and a title)
Hope this helps
Cheers,
Rhys
Edited to make it look nicer.
  댓글 수: 1
Rhys
Rhys 2013년 6월 25일
It seems that the function you want to make is the same as fplot.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by