que consiste el error "as a function is not supported "

x=0:0.01:2
f=@(x) x.^2;
f= integral(f)
no me deja usar la funcion integral, tiene un error de Execution of script integral as a function is not supported:
C:\Users\Javier\OneDrive\Documentos\MATLAB\integral.mlx

답변 (2개)

Torsten
Torsten 2023년 2월 15일
이동: Torsten 2023년 2월 15일
syms x
f = x^2;
I = int(f,x,0,2)
I = 
or
f=@(x) x.^2;
I = integral(f,0,2)
I = 2.6667
Walter Roberson
Walter Roberson 2023년 2월 15일

0 개 추천

you named your own Livescript "integral" and it is in your current folder. When matlab encounters the call to integral() in your code, there is a specific order it searches in. It checks to see if integral is a variable in your workspace. It checks to see if you used "import" to bring it in from a package. It checks to see if the directory containing the script has a subdirectory named "private". It checks to see if there is integral.slx integral.mdl integral.p integral.m integral.mlx and probably some others (exact order might not be exactly what I listed.) Only after the current directory is searched and not found does it look in the standard directories to find matlab's own integral functions.
So the fact that you named your Livescript integral.mlx is causing your script to be found instead of the matlab integral() function. And then matlab complains because your integral.mlx is not a function.
Moral of the story: avoid naming your script the same as something that you might need to call.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2023년 2월 15일

답변:

2023년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by