how to plot a function handle on matlab 7 ?

13 Ansichten (letzte 30 Tage)
HeadingUpHigh
HeadingUpHigh am 20 Apr. 2018
Kommentiert: Star Strider am 21 Apr. 2018
my code is i'm asking the user to input a funtion and i transform it to a handle one (note that i'm using the matlab 7.0 R14) :
funstr = input('• Please enter your function here : ', 's');
f = eval( ['@(x) ' funstr ] );
how can i possibly do the plot of this between the two points a and b? i keep getting errors
??? Index exceeds matrix dimensions
or
??? Error using ==> plot Conversion to double from function_handle is not possible.
i tried it with plot and fplot and none of them is working !
thanks for helping in advance.

Akzeptierte Antwort

Star Strider
Star Strider am 20 Apr. 2018

You need to evaluate the function in the plot call.

Example

fun = @(x) x.^3 - 8*x.^2 + 10;
x = linspace(-5, 5);
figure
plot(x, fun(x))
grid
  6 Kommentare
HeadingUpHigh
HeadingUpHigh am 21 Apr. 2018
thanks mate, you've been very helpful.
Star Strider
Star Strider am 21 Apr. 2018
As always, my pleasure.
The File Exchange has several functions that add necessary capabilities missing in earlier MATLAB versions. (Many of these have been incorporated in MATLAB and the Toolboxes since.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by