Error: Attempt to execute SCRIPT mesh as a function

2 ビュー (過去 30 日間)
ryecatcher
ryecatcher 2020 年 2 月 19 日
コメント済み: ryecatcher 2020 年 2 月 19 日
Dear All:
I am trying to run a simple live script:
%mesh
x1=linspace(-pi, pi, 20);
x2=linspace(-10, 10, 30);
%Call meshgrid to create a cartesian
[X1, X2]=meshgrid(x1, x2);
%Evaluate the function at these (X1, X2) pairs
Z = cos(X1).*X2;
figure
mesh(X1, X2, Z)
In the beginning, clicking 'Run Section' will run the code correctly. At that time, the script has not been saved yet. So the script's name was 'untitled.mlx'. Then I saved the script as 'mesh.mlx'. Now, clicking 'Run Section' has the red error: Attempt to execute a SCRIPT mesh as a function: /MATLAB Drive/mesh
Why no error before the live script was saved and error afterwards? My screenshot is attached.
Thank you very much for your help. I greatly appreciate it.

採用された回答

Alex Mcaulley
Alex Mcaulley 2020 年 2 月 19 日
Because your live script has the same name than the function mesh and when you call this function, in fact you are calling your live script. -> Change the name of your script
  1 件のコメント
ryecatcher
ryecatcher 2020 年 2 月 19 日
Thank you very much for your help. I see. Now I have renamed the file 'mesh.mlx' to 'my_mesh.mlx' and it has worked.
I greatly appreciate your help. Have a nice day!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by