Initializing Simulink Model (Run a function once)
Ältere Kommentare anzeigen
Hi,
I have a model where I get output from an Aurduino Uno board. In this model, I have to make some sort of initialization (to calculate offset and calibrate readings). Typically, this will be done using a loop function that runs only once. Since I couldn't find a way to do that I used MATLAB Function block and made the signal go through before being fed to the model. The function is as follows:
function y = fcn(u)
u_calc = 0;
for i = 1:10
u_calc = u_calc + u;
pause('0.1');
end
u_calc = u_calc/10;
y = u-u_calc;
Basucally there is no way to make the loop conditionally run once, since I can't just set an "if" condition + a flag beacuse of the flag variable scope. How can I get around this? Or is there another approach to perform such task?
Your help is much appreciated.
Akzeptierte Antwort
Weitere Antworten (2)
saiful azimi
am 30 Dez. 2020
1 Stimme
Maybe you can refer to this: https://www.mathworks.com/matlabcentral/answers/363992-how-to-execute-subsystem-once-at-startup
saiful azimi
am 30 Dez. 2020
0 Stimmen
Can you give some details on what model do you use for Arduino UNO? Do you use MATLAB code or Simulink?
1 Kommentar
Kategorien
Mehr zu Arduino Hardware finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

