matlaboctavesimulinkscilabxcos

How to set parameters in Scilab blocks from SciPad?


I don't know if anyone faced the same problem! In MATLAB, we can easily set the parameters of Simulink blocks from m-files. For example, we can change the coefficients of transfer functions, PID gains, step-input magnitude, simulation time, etc.

In Scilab, everything is unknown! Actually, I don't know if this feature is available in Scilab or not!

Any helpful feedback or hint will be highly appreciated.

Thank you


Solution

  • You can easily adapt parameters in Xcos blocks using a Scinotes script.

    1. Set up the Xcos diagram with all the blocks needed.
    2. Open the Context menu in Xcos (Simulation -> Set Context). This will open a blank page where you can define an initial value(-s) of intrest.
    3. Suppose you have a sine generator in Xcos and need to change its frequency.
    4. Type frequency=1; in the Context window and close it with OK
    5. Open the sine genrator block and type the same name ('frequency') in the apropriate window.
    6. You cannot interchange the order of the previous steps ! A name and value must be present in Context before they an be assigned to an existing block in the diagram.
    7. From now on the frequency value is taken from the Context variable.
    8. Now create an new Scinotes script (it can have the same name as the Xcos diagram).
    9. In this script you set the wanted frequency value as follows: Context.frequency = 10; Te value in Xcos is the default, and is superseded by the Scinotes value each time the Xcos diagram is run from within Scinotes.
    10. Run the Xcos diagram from the script by using the xcos_simulate() function which allows you to send new Context information to Xcos before running a simulation.
    11. From this point on you only need Scinotes to run your simulation, gather data (e.g. with a TOWS_c block) and analyse results !

    Sincerely, Mark