why do I receive error "Not enough Argument"
조회 수: 181 (최근 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
채택된 답변
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.
추가 답변 (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에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!