Method Input within Function (or something like that)

조회 수: 3 (최근 30일)
Lucas Russi
Lucas Russi 2019년 10월 28일
답변: Lucas Russi 2019년 10월 28일
function [Matrix,SubcomponentMatrix] = myfunction(other things + SubcomponentMatrix)
for i=1:length(something)
element = Nodes(List{i,2}).(List{i,3})...
(List{i,6});
element = update(element,SubcomponentMatrix,i);
end
where element is a class instance
and update is a method
function obj = update(obj,SubcomponentMatrix,i)
for m=3:sum(~cellfun(@isempty,SubcomponentMatrix(i,:)),2) %length var therefore only consider non empty cells
x = SubcomponentMatrix{i,m}.property1;
y(m-2,1) = SubcomponentMatrix{i,m}.y(x+1);
end
obj.K = 1-min(y);
end
SubcomponentMatrix is a cell that contains classes of a different type
The first two colums of SubcomponentMatrix contain some sort of ID and don't contain relevant information
I'm pretty sure I didn't catch something basic on OOP - the error is "not enough Input arguments" in update
I'm very grateful for any help.
  댓글 수: 4
Guillaume
Guillaume 2019년 10월 28일
Ok, so the problem is with myfunction, not with update. What is the actual signature of myfunction, and more importantly, how did you call it?
Have you really given us the full text of the error message? The answer to these questions would have been in the rest of the error message.
Lucas Russi
Lucas Russi 2019년 10월 28일
편집: Guillaume 2019년 10월 28일
Error in myfunction (line 19)
element = update(element,SubcomponentMatrix,i);
Error in Process (line 51)
[A] = myfunction(System_Matrix, Nodes,...
Error in Main (line 101)
Process
Error Run (line 162)
Main
no sorry, thats everything

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2019년 10월 28일
What this error is telling you:
Not enough input arguments.
Error in myfunction (line 19)
element = update(element,SubcomponentMatrix,i);
is that when the code reaches line 19 of myfunction you try to use one of the input arguments of myfunction but that input argument wasn't specified when you called myfunction. That not enough input arguments refers to myfunction, not to update. The reason it occurs on line 19 is because that's the first line where you try to use that missing input.
Since both element and i are created inside the function, it must be SubcomponentMatrix that's missing. Unfortunately, the full call of myfunction (what a bad name!) is hidden in the ... you've used to replace the rest of the error but clearly at line 51 of process, you're not passing enough input arguments to myfunction. If you don't pass the SubcomponentMatrix input, then yes, you can't use it.

추가 답변 (3개)

Lucas Russi
Lucas Russi 2019년 10월 28일
prob.PNG

Lucas Russi
Lucas Russi 2019년 10월 28일
thanks for taking time to solve my problem - but I do pass the SubcomponentMatrix.
that shouldnt be the issue.
Is there any other immaginable reason why this doesnt work?

Lucas Russi
Lucas Russi 2019년 10월 28일
nope all good -
I defined 12 inputs in process and 13 in my function - which inst actually called my function

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by