Error when getting function to test testprime

3 ビュー (過去 30 日間)
Hong
Hong 2024 年 2 月 24 日
編集済み: Walter Roberson 2024 年 2 月 24 日
Hi i was doing the function but i kept getting this i wonder what did I do wrong

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 2 月 24 日
The
clear; clc
makes your code into a script, and makes the declaration of testprime there into a local function for the script.
To make your code work, you need to delete the
clear; clc
  2 件のコメント
Hong
Hong 2024 年 2 月 24 日
after delete the clear;clc i got another erro
Walter Roberson
Walter Roberson 2024 年 2 月 24 日
編集済み: Walter Roberson 2024 年 2 月 24 日
When you run a function that expects input parameters, and you do not pass in the input parameters, then MATLAB does not prompt you for the input parameters, and MATLAB does not go searching around trying to find a variable that has the same name as the input parameter.
It is considered valid in MATLAB to (attempt to) run a function without passing in all of the parameters, since code can detect that input parameters have not been passed and can make appropriate adjustments. For example,
if nargin < 1
error('You forgot to specify x');
end

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by