フィルターのクリア

Error "Not enough input arguments" when using publish tab (function with input arguments)

13 ビュー (過去 30 日間)
Michelle Ghrist
Michelle Ghrist 2022 年 9 月 16 日
コメント済み: Michelle Ghrist 2023 年 3 月 4 日
I'm trying to publish a function with input arguments. Here's a simple test file:
______
function y=mytest(a,b)
y=a+b;
end
______
Typing "mytest(3,4)" at the command prompt works as expected.
To publish, I select "Edit Publishing Options" in the Publish tab, then type "mytest(3,4)" in the MATLAB expression box(with output file format PDF) and hit the "Publish" button and get this error:
Not enough input arguments. -> Error in mytest (line 2) -> y=a+b;
This approach used to work, a few years ago, but for some reason no longer works. I'd prefer to be able to use the Publish tab rather than running "publish(...) " from the command window, as I'm trying to find an EASY way for beginning students to accomplish this to submit their homework.

回答 (1 件)

Ayush Yadav
Ayush Yadav 2022 年 9 月 19 日
Hi Michelle,
You should use the default publishing preferences if your code requires no input arguments.
However, if your code requires input arguments, or if you want to specify output settings, code execution, or figure formats, then specify a custom configuration.
The following page describes how to specify a custom configuration:
  2 件のコメント
Khondaker
Khondaker 2023 年 3 月 4 日
Hi, can you please tell me the process step by step how to fix this error while publishing?
Michelle Ghrist
Michelle Ghrist 2023 年 3 月 4 日
Here's what I took away and was able to get working:
To publish a function m-file where you send inputs or outputs to/from your function (or to run something more than just the function), create a script (non-function) file that contains your function file at the bottom. At the top of the script file, give the command(s) that call your function. In this way, you can call the function multiple times with different inputs. For example, I saved this file as mytest.m and published it; it runs my function addt multiple times.
addt(3,4)
addt(5,6)
function y=addt(a,b)
y=a+b;
end
[You can have multiple "subfunctions" at the bottom of a script file.]

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

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by