matlabsimulinkstateflow

No constructor 'Stateflow.State' with matching signature found. Error Matlab


I'm trying to create State block from sflib (stateflow library) :

chart = add_block('sflib/Chart', 'autoDS/Chart'); %Create Chart Block
state = Stateflow.State(chart); %Create State in Chart Block
state.Name = 'CMD_28V_Avion';
open_system('autoDS');

It returns me "No constructor 'Stateflow.State' with matching signature found" error. How can i fix it please ? I don't know if it's a syntax or a library error as i saw on many post.


Solution

  • add_block returns a handle to the added block (which for a state chart is actually a subsystem.) It does not return a handle to a chart, which is what Stateflow.State requires as its input. Hence the error.

    You need,

    add_block('sflib/Chart', 'autoDS/Chart'); %Create Chart Block
    rt = sfroot;
    m = rt.find('-isa', 'Simulink.BlockDiagram', '-and', 'Name', 'autoDS'); % block diagram
    ch = m.find('-isa','Stateflow.Chart', '-and', 'Name', 'Chart'); % chart
    st = Stateflow.State(ch); % state
    st.Name = 'CMD_28V_Avion';
    open_system('autoDS');
    

    See the Access the Model Object and Access the Chart Object sections of Create Charts by Using the Stateflow API