not enough input arguments
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
function test(num1, num2,small,s)
load (small, num1, num2)
s = sum(num1, num2)
end
this the code for this i'm getting these errors
Not enough input arguments.
Error in test (line 3)
load (small, num1, num2)
採用された回答
KALYAN ACHARJYA
2019 年 9 月 4 日
編集済み: KALYAN ACHARJYA
2019 年 9 月 4 日
I assumed that num1 and num2 are number
function s=test(num1, num2)
s=num1+num2;
end
Save the above function as test.m file name, and pass the inputs arguments form main scripts or command window, like as follows
Command Window:
>> result=test(4,6)
result =
10
You have to pass the inputs arguments from differnt Matlab scripts to Matlab test.m function file.
see here
5 件のコメント
@aarthy, You clearly do not know how to write a function, so learn that first. Kalyan has shown you what the proper syntax for your function probably should be.
The function that you have defined is a function that has 4 inputs and no output. Of those 4 inputs, it only uses the first three and discards the 4th one replacing it by another value calculated inside the function. Since the function has no output, it actually doesn't matter what it does, nothing ever comes out of it.
Now the reason you got the error is that you called the function without passing the required number of inputs. Perhaps you just pressed the run button. The error occured on line 3 as that's where your function first tries to use the missing inputs.
Even if you'd called the function with the required 3 inputs, it still would have errored unless the small input variable contained the path to a valid mat file, and the num1 and num2 variables contained the names of variables within that mat file. But in that case. an error would have occured on the following line since summing variable names (as oppsoed to summing variables) doesn't make sense.
aarthy reddy R
2019 年 9 月 4 日
thanks KALYAN ACHARJYA, i understood my mistake in stating function with inappropriate input arguments.
I am not able to understand the error in load statement thats why i included that file name "small" in input arguments of function. can you help to load small excel file in which values for num1, num2 are used to perform sum action.
i have changed the function stating in following code
but i am getting errors as
Undefined function or variable 'small'.
Error in test (line 3)
load (small, num1, num2)
function s = test(num1, num2)
load (small, num1, num2)
s = num1 + num2;
end
Guillaume
2019 年 9 月 4 日
Note that I've given you the link to the load documentation. I'm not sure what you're trying to do with that load call, but it's certainly not correct.
You are calling load with 3 inputs. If you had a .mat file called myfile.mat containing amongst other things, the variables myvar with value [1, 2, 3] and myothervar with value [4, 5; 6, 7], then the following would work:
small = 'myfile.mat';
num1 = 'myvar';
num2 = 'myothervar';
load(small, num1, num2);
%at this point, two new variables would exist
%myvar = [1, 2, 3]
%myothervar = [4, 5; 6, 7]
You get an error because within the function test, there is no small variable. Perhaps it should be an input to the function? However, if num1 and num2 are numbers as their names imply, your load makes no sense.
Perhaps, you're trying to load the variables called num1 and num2 from a file called small, in which case:
load small.mat num1 num2; %no ()!
%or
load('small.mat', 'num1', 'num2'); %if using () enclose text in ''
But in that case, there's no point in asking for inputs num1 and num2 since they get immediately overwritten by load.
aarthy reddy R
2019 年 9 月 12 日
編集済み: aarthy reddy R
2019 年 9 月 12 日
i am having error only in line 2 because of load
the error is :Error using load
Unable to read file 's'. No such file or directory.
Error in test (line 2)
load s
but i have imported the s file still dont know ..... please look into the picture i have attached
function out = test(num1, num2)
load s
out = num1 + num2;
end
i want to know how to load an excel sheet so those values can be used in this function
Guillaume
2019 年 9 月 12 日
load s
will load the content of a file called s into the workspace of your function. It won't do anything else.
but i have imported the s
I'm not sure what that means exactly. But Whatever you've done outside of the function is irrelevant if you don't pass the stuff as inputs to the function
i want to know how to load an excel sheet so those values can be used in this function
This has absolutely nothing to do with load. You'd use xlsread or preferably readtable to import data from excel, then pass the data as an input to the function.
%data = readtable('C:\somewhere\somefile.xlsx'); %import data from excel as a table
result = test(data.Var1, data.Var2) %call the function passing two columns from the imported data
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Import from MATLAB についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
