send values from AppDesigner app to Stateflow?

7 views (last 30 days)
Hey,
I've been using following instruction to connect my stateflow algorithm with AppDesigner: https://www.mathworks.com/help/stateflow/ug/sf4ml-lamp-example.html
This does not explain how I can exchange values such as double or integers from the app to stateflow or vice versa. Can anybody show me how to do that? I'm currently trying to apply values to variables from my app to stateflow but it does not work despite proper coding. For instance, following code should apply the slider value from the app GUI to the variable in stateflow:
app.NameOfStateflowProgram.NameOfStateflowVariable = app.Slider.Value;
The program enters and executes the code succesfully and changes the value within the app but not within stateflow.
Thanks for your help

Answers (1)

Yash
Yash on 27 Sep 2023
Hi Manuel,
I understand that you are facing difficulties in linking variables from App Designer to Stateflow. The instructions to establish this connection can be found in the example you mentioned. You can refer to the specific section on how to establish this connection by visiting the following link:
To verify the example, I created an app that adds two user-provided integers in Stateflow, following the instructions provided. Here are the steps you can follow:
1. Create your Stateflow model and ensure that the variables you want to link from App Designer are defined as local data in Stateflow. Save the Stateflow model file. In my case, I had three local variables, 'a', 'b' and 'out'. I saved the file as 'adder_logic.sfx'.
2. In App Designer, create a private property to store the handle of the Stateflow Model as shown below:
properties (Access = private)
adder_handle
end
3. In the startup function, initilize the model and assign it to the handle.
function startupFcn(app)
% I have taken two sliders for values of a and b and an edit field to display the sum.
app.adder_handle = adder_logic('a',app.aSlider.Value, 'b', app.bSlider.Value,'out', 0);
app.outputEditField.Value = app.adder_handle.out;
end
4. Add a callback function to handle value changes, as follows:
function aSliderValueChanged(app, event)
app.adder_handle.a = app.aSlider.Value;
pause(2) % Optional delay to allow Stateflow to update
app.outputEditField.Value = app.adder_handle.out;
end
By following these steps, you will be able to link the variables from App Designer to Stateflow.
Hope this helps!
Best Regards
Yash

Categories

Find more on Complex Logic in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!