Problem with MATLAB function
Show older comments
Hello, everyone!
I'm trying to do the "real-time" computation with Simulink. For this I try the MATLAB Function with the system on pic. The subsystem Sys1 consits of two aperiodic links. The MATLAB should compute the optimal control for this system.
But I meet some problems with this.
The first one and most hard is that I can't find the way to programmatically stop or start some of the code execution in MATLAB function. In my case, I need to do some computations with Inputs of MATLAB function only when Output of the Sys1 x1 is smaller than 0.8 or greater then 1.2.
For simplification of the poblem I do not provide a calculating part of the code, but only the answers it would give.
Inside MATALB Function I have the following code:
function Control = fcn(Clock,x1,x2,A1,B1,A2,B2)
%Duration of control intervals to "Start" the system
TIME0=[0.416398568470955,0.306200290286777];
%4 is taken because of the external influence is
%attached on 4 sec
if Clock<=4
BEB=0;
else
BEB=1;
%Duration of control intervals to return the system to nominal output
TIME0=[0.3506 0.1779];
end
if BEB==1
if 4<=Clock&&Clock<=TIME0(1)+4
Control=5;
elseif Clock>=TIME0(1)+4&&Clock<=sum(TIME0)+4
Control=0;
else
Control=2.298498;%Normal rate of control that gives the nominal output
end
else
if Clock<=1
Control=0;
else
if 1<=Clock&&Clock<=TIME0(1)+1
Control=5;
elseif Clock>=TIME0(1)+1&&Clock<=sum(TIME0)+1
Control=0;
else
Control=1.53233220962305;%Normal rate of control that gives the nominal output
end
end
end
This code is horrible, so I want to make something that will automatically.
If anyone will need the system parametrs - that they are: A1=-2.0408; B1=1.3318; A2=-2.0833; B2=2.0833

Thanks in advance!
Answers (0)
Categories
Find more on Tuning Goals 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!