# Simulate this diagram in batch mode and perform bode plotting of transfert function using post\_xcos\_simulate

**URL:** <https://scilab.discourse.group/t/simulate-this-diagram-in-batch-mode-and-perform-bode-plotting-of-transfert-function-using-post-xcos-simulate/727>\
**Category:** Xcos\
**Created:** [November 19, 2024, 8:05pm UTC](https://scilab.discourse.group/t/simulate-this-diagram-in-batch-mode-and-perform-bode-plotting-of-transfert-function-using-post-xcos-simulate/727 "2024-11-19T20:05:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manfrind](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Manfrind](https://scilab.discourse.group/u/Manfrind)\
**Post date:** [November 19, 2024, 8:05pm UTC](https://scilab.discourse.group/t/simulate-this-diagram-in-batch-mode-and-perform-bode-plotting-of-transfert-function-using-post-xcos-simulate/727/1 "2024-11-19T20:05:48Z")

</div>

I want to plot a bode diagram out of a xcos transfer function. Therefore I tried to execute the example in the help browser in the xcos\_simulate command.  
The file SCI/modules/xcos/demos/Command.zcos is given there. When I try to run the code which is given in the help, I get an error message.  
“Error in post\_xcos\_simulate: ending simulation.”  
The figure is shown, but the bode plot does not start.  
What is the problem here? The example in the help should work properly I think? Scilab 2024.1.0

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [November 20, 2024, 8:14am UTC](https://scilab.discourse.group/t/simulate-this-diagram-in-batch-mode-and-perform-bode-plotting-of-transfert-function-using-post-xcos-simulate/727/2 "2024-11-20T08:14:00Z")

</div>

Hello and welcome to Scilab’s Discourse,

The example source seems broken (we are going to fix this, sorry), you can modify it like this:

```scilab
importXcosDiagram("SCI/modules/xcos/demos/Command.zcos")

// Clear any pre_xcos_simulation;
clear pre_xcos_simulate;

function post_xcos_simulate(%cpr, scs_m, needcompile)
    // Retrieve all objects
    objs = scs_m.objs;

    //Looking for CLR block
    for i=1:size(objs)
        if objs(i).gui == "CLR" then
            clrBlock = objs(i);
            break;
        end
    end

    // Check if we found some CLR
    if ~exists("clrBlock","local") then
        disp("No CLR block found.")
        return
    end

    // Retrieve exprs
    exprs = clrBlock.graphics.exprs;
    s = poly(0,'s');
    num = evstr(exprs(1));
    den = evstr(exprs(2));
    h = syslin('c', num/den);
    // Open new figure then plot Bode
    scf(max(winsid())+1);
    bode(h, 0.01, 100);
endfunction

xcos_simulate(scs_m, 4);

```

S.

---

<div class="post-metadata">

**Author:** ![Manfrind](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Manfrind](https://scilab.discourse.group/u/Manfrind)\
**Post date:** [November 24, 2024, 6:30pm UTC](https://scilab.discourse.group/t/simulate-this-diagram-in-batch-mode-and-perform-bode-plotting-of-transfert-function-using-post-xcos-simulate/727/3 "2024-11-24T18:30:48Z")

</div>

Yes, now it works. Thanks for your prompt reply.
