I am using the matlab function block in simulink. I need it to continuously read its inputs and change its outputs. The problem is that I must declare my start position as zero. Then my function runs and increments as desired. THEN it seems to enter the function again and reset to zero (as it would). I need to declare the variable to zero the very first time through the function then all times after use the value that it generated before. See code below:
function y = fcn(sEMG5,sEMG6) %#codegen % %set original servo positions to zero % servo2=0; % servo3=0; % servo4=0; % servo5=0; %incrememt servo position when threshold is met if sEMG5 > 150 servo2 = servo2+3; elseif sEMG6 > 150 servo2= servo2-3; end %keep servo position in allowable range if servo2 > 180 servo2 = 180; elseif servo2 < 0 servo2 = 0; else servo2=servo2; end y = servo2;
So my problem is how to declare servo2 as zero once and then use the value that y was all successive times through.
You could also use a persistent variable inside your MATLAB function block:
function y = fcn(sEMG5,sEMG6) %#codegen persistent servo2; % set original servo positions to zero the % first time this function is invoked if isempty(servo2) servo2=0; end % Use servo2 here ...
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.