why do I receive error "Not enough Argument"

조회 수: 153 (최근 30일)
KEYVAN PEBDANI SAHRAEI
KEYVAN PEBDANI SAHRAEI 2020년 11월 6일
댓글: KEYVAN PEBDANI SAHRAEI 2020년 12월 13일
Hello
I am writting codes to a s-function block to create demo or animate of a liquid Tank ,but I have a problem which is "not enough Arguments".I am not sure if you know what is the problem,I have paste my written codes below.
Thank you
function [sys,x0,str,ts,setPt1,setPt2,waterx1,vessel1Hndl,vessel1Ht, vesselHndlList,waterY1,vessel2Hndl,lineHndl1,lineHndl2]=vesseldemo2project (u,flag,t,x)
switch flag==4
case 0
[sys,x0,str,ts,vesseldemo2project]=mdlInitializeSizes;
get(vesseldemo2project,'UserData') =vesselHndlList;
get( vesselHndlList(1),'YData');
yData(1)=yOffset;
yData(3:4)=[1 1]*u(2)+yOffset;
set( vesselHndlList(1),'YData',yData);
yData=get(x(2),'YData');
yData([3 4])=[1 1]*u(2)+yOffset;
set(x(2),'YData',yData);
yData=[1 1]*u(1)+1;
set(x(3),'YData',yData);
case 2
%Tank body details.................................
sys=mdlUpdate(t,x,u);
vessel1Ht=1;
vessel1Wid=1;
vessel1Init=0;
setPt1=0.5;
setPt2=0.75;
vesselx=[0 0 1 1]-0.5;
vesselY=[1 0 0 1];
line(1.1*vesselx*vessel1Wid+1,vesselY*vessel1Ht+0.95,'LineWidth',2,'Color','black');
% Draw the water..............................................
waterx1=vesselx*vessel1Wid+1;
waterx=vesselY*vessel1Init+1;
x=patch(waterx,waterx,'blue','EdgeColor','none');
% Draw the gray wall............................................
waterY1([1 2 5])=vessel1Ht*[1 1 1]+1;
waterY([3 4 ])=x*[1 1 ]+1;
vessel2Hndl=patch(waterx,waterY,[.9 .9 .9],'EdgeColor','none');
case 3
str = [];
ts = [.1 0];
vessel1Wid=1;
vessel1Ht=1;
vessel1Init=0;
setPt1=0.5;
setPt2=0.75;
vesselx=[0 0 1 1]-0.5;
vesselY=[1 0 0 1];
waterx1=vesselx*vessel1Wid+1;
waterx=vesselY*vessel1Init+1;
waterY1([1 2 5])=vessel1Ht*[1 1 1]+1;
waterY([3 4 ])=vessel1Init*[1 1 ]+1;
vessel1Hndl=patch(waterx,waterx,'blue','EdgeColor','none');
vessel2Hndl=patch(waterx,waterY,[.9 .9 .9],'EdgeColor','none');
lineHndl1=line([0 0.4],setPt1*[0.5 0.5]+1,'Color','red','LineWidth',4);
hlod on
lineHndl2=line([0 0.4],setPt2*[0.75 0.75]+1,'Color','red','LineWidth',4);
hold on
set(gcf, ...
'Color',[.9 .9 .9], ...
'UserData',[vessel1Hndl vessel2Hndl lineHndl]);
set(gca, ...
'XLim',[0 2],'YLim',[0 3.5], ...
'XColor','black','YColor','black', ...
'Box','on');
axis equal
xlabel('Water Level Control','Color','black','FontSize',10);
set(get(gca,'XLabel'),'Visible','on');
x0=0;
otherwise
error(message('vesseldemo:vesseldemo2project:UnhandledFlag', flag));
end
  댓글 수: 2
Piyush Aggarwal
Piyush Aggarwal 2020년 11월 9일
"Not enough arguments" error is simply an indicative of the fact that you are calling some MATLAB/user-defined function with the wrong syntactical signature. You will need to pass correct number of inputs arguments to any function. Look closely at the exact error message you are recieving. It will tell you which line and which function is causing the trouble.
KEYVAN PEBDANI SAHRAEI
KEYVAN PEBDANI SAHRAEI 2020년 11월 9일

There is not any error in command lines but at the end I have the problem. Thank you for advicing.

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 13일
Note: you are using a Level 1 S-Function inside of Simulink
get(vesseldemo2project,'UserData') =vesselHndlList;
That attempts to assign a value to an array named get indexed at integer locations indicated by vesseldemo2project and the offsets calculated by converting the character vector 'UserData' into character codes. This is not at all likely to be what you want.
More likely would be
vesselHndlList = get(vesseldemo2project,'UserData');
If this is not enough to fix the problem, you will need to post more of the error message, showing which line it is complaining about.
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 12월 13일
The file is intended to be called from Simulink by configuring it through an S-Function Block. If you call it at the MATLAB level, you need to pass in at least four variables (possibly 5 for that code). The four major ones are documented at the link I posted at the top of my Answer.
KEYVAN PEBDANI SAHRAEI
KEYVAN PEBDANI SAHRAEI 2020년 12월 13일
Thank you

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

추가 답변 (1개)

Abhisek Pradhan
Abhisek Pradhan 2020년 12월 13일
This may be a case of defining and calling the function in the same script. If this is the case try separating them out and see if it works.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by