not enough input arguments
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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일
0 개 추천
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
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
