I have simulated a system using pure simulink blocks. Later I substituted some of the subsystems by commands in a matlab embedded function. The results are completely different. What could cause such diverge results?
Could you elaborate on "completely different"? Are the results only differing in value but still following the same trends (i.e. lost of accuracy) or are they plain wrong?
My experience with Simulink to hardware (FPGA) showed both lost of accuracy (Bit-width, floating/fixed point representation) and errors (delays, time modeling).
the rends are different. In other words, the pure simulink model provides the expected trend while the simulink file in which a few subsystems are replace by equivalent embedded matlab functions does not provide the expected trend.
Is the embedded matlab function execution time continuous or discrete? Because I remember having this kind of issues with S-functions blocks, where execution time differs from solver steps.
I usually get good results using following simulation configuration in my experimental validations (where I use C language funtions): In your Simulink diagram, menu Simulation/Configuration parameters; Solver options, Type: Fixed-step, Solver: ode1 (Euler), Periodic sample.. : Unconstrained, Fixed-step (fund. sample time): 2e-6, Tasking mode for periodic sample times: Single Tasking. Then I use 2e-6 as a simulation sample time and about 1e-4 or greater for the controllers and estimators (previously dicretized).