Problem with the level 2 M file S function

1 次查看(过去 30 天)
I wrote the lvl 2 M file which consists of the If Elseif loop. and my i/p to the S function block is two sine wave blocks. Below is the logic which I used...
function Update(block)
vsd = block.InputPort(1).Data;
vsq = block.InputPort(2).Data;
%k = block.Dwork(1).Data;
%x = block.Dwork(2).Data;
if vsd>0 & vsq>=0 & vsd>vsq;
k=1;
elseif vsd>0 & vsq>=0 & vsd<=vsq;
k=2;
elseif vsd<=0 & vsq>0;
k=3;
elseif vsd<0 & vsq<=0 & vsd<vsq;
k=4;
elseif vsd<0 & vsq<0 & vsd>=vsq;
k=5;
elseif vsd>=0 & vsq<0;
k=6;
end
block.Dwork(1).Data = k;
%end function
Now the question is it gives me the desired o/p only for the smaller simulation times, as I increased the simulation times, I didn't get the o/p which I want. It's like this If Elseif loop is true only for the first one or two cycles of the sine waves only.
So can anyone help me??
  1 个评论
Kaustubha Govind
Kaustubha Govind 2012-7-12
Perhaps you should set breakpoints in your code to debug the issue? It's hard for us to tell without looking at your input signal.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by