why do I receive error "Not enough Argument"
156 ビュー (過去 30 日間)
古いコメントを表示
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
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.
採用された回答
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
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.
その他の回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File 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!