Is there any known eason why my level 2 matlab S-function runs slow
Show older comments
Please take a look at the following very simple level 2 matlab S-function, do you please know any reason why it should run slow.
By the way How do I past the matlab code in this textbox so that it can be readable?
/////////////////////////////////////////////////////////////
function handFunctionSeq(block)
setup(block);
function setup(block)
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 4;
% Setup port properties to be inherited or dynamic
% % Override input port properties
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = true;
%
% % Override output port properties
%opeing of hand: thumb
block.OutputPort(1).Dimensions = 1;
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.OutputPort(1).SamplingMode = 'sample';
%opening of hand: fingers
block.OutputPort(2).Dimensions = 1;
block.OutputPort(2).DatatypeID = 0; % double
block.OutputPort(2).Complexity = 'Real';
block.OutputPort(2).SamplingMode = 'sample';
%closing if hands: thumb
block.OutputPort(3).Dimensions = 1;
block.OutputPort(3).DatatypeID = 0; % double
block.OutputPort(3).Complexity = 'Real';
block.OutputPort(3).SamplingMode = 'sample';
%closing of hand: fingers
block.OutputPort(4).Dimensions = 1;
block.OutputPort(4).DatatypeID = 0; % double
block.OutputPort(4).Complexity = 'Real';
block.OutputPort(4).SamplingMode = 'sample';
% Register parameters
block.NumDialogPrms = 4;
block.SampleTimes = [-1 0];
block.SimStateCompliance = 'DefaultSimState';
%%Register methods
block.RegBlockMethod('PostPropagationSetup',@DoPostPropSetup);
block.RegBlockMethod('Outputs', @Outputs);
block.RegBlockMethod('Update', @Update);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('SetInputPortSamplingMode',@SetInputPortSamplingMode);
%end setup
function DoPostPropSetup(block)
block.NumDworks = 1;
block.Dwork(1).Name = 'x1';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0; % double
block.Dwork(1).Complexity = 'Real'; % real
block.Dwork(1).UsedAsDiscState = true;
function Start(block)
block.Dwork(1).Data =0;
%endfunction
function Outputs(block)
%delays in samples
delay_close_open=block.DialogPrm(1).Data;%e.g=256*3 samples
delay_thumb_close=block.DialogPrm(2).Data;%e.g=70 samples
delay_fingers_open=block.DialogPrm(3).Data;%e.g=70 samples
trialLength=block.DialogPrm(4).Data;%e.g=256*5 samples
block.OutputPort(1).Data=0;
block.OutputPort(2).Data=0;
block.OutputPort(3).Data=0;
block.OutputPort(4).Data=0;
%opening of hands
block.OutputPort(1).Data = block.InputPort(1).Data;%thumb signal sent first
if(block.Dwork(1).Data>=delay_fingers_open)
block.OutputPort(2).Data =block.InputPort(1).Data;%delayed fingers signal follows
else
block.OutputPort(2).Data=0;
end
%closing of hand
if(block.Dwork(1).Data>=delay_close_open)
if(block.Dwork(1).Data<=trialLength)%delaying closing of hand in samples
% disable opeinning of hand when closing hands
block.OutputPort(1).Data=0;
block.OutputPort(2).Data=0;
%initiate closing of hand starting with the fingers
block.OutputPort(4).Data = block.InputPort(1).Data;%fingers signal sent first
if(block.Dwork(1).Data>=delay_thumb_close+delay_close_open)
block.OutputPort(3).Data =block.InputPort(1).Data;%thumb signal comes after
else
block.OutputPort(3).Data=0;
end
else
%i.e the going back to opeing of hands. This is the end of the
%circle so we can go back to hand opening and reseting our work
%vectors
block.Dwork(1).Data=0;
block.OutputPort(2).Data=0;%avoid the spike of channel 2
end
else
end
%end Outputs
function Update(block)
block.Dwork(1).Data =block.Dwork(1).Data+1 ;
%end Update
function SetInputPortSamplingMode(s, port, mode)
s.InputPort(port).SamplingMode = mode;
///////////////////////////////////////////////////////////////
2 Comments
Kaustubha Govind
on 17 Jul 2012
I formatted your question for you, but please see http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question
bethel o
on 17 Jul 2012
Accepted Answer
More Answers (0)
Categories
Find more on Naming Conventions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!