Using App Designer for Setting Inputs to a Simulink Model and Reading The Output Data of the Model back from App Designer

43 visualizzazioni (ultimi 30 giorni)
Hello,
I am working on an app that is supposed to pass the data (as an array) to a simulimk model as input, run the model for the each element of the array, get each output value formed by the simulink model, form an array with them and pass the ouput data (array) to the app designer back.
  • I am able to pass constant-type data (i.e. 4) from app designer to the simulink model by using set_param function. However, that doesn't work for arrays; so, I just cannot set an array from the app desiner as the value of a constant block inside the simulink model. Therefore, I used a 'for' loop inside the app in order to pass each element of the array to the simulink model as inputs. I am not hundred percent sure whether it works, though.
  • I cannot get the output values from simulink model to app designer neither as arrays nor as constant values. Since I am not able to pass an array to the simulink model, I just tried to assign random constant input values inside the simuilnk model but I couldn't find a way to pass the output value from the model to the app designer.
My questions are:
  • How can I pass an array from app designer to the simulink model as an input?
  • How can I pass a constant value or an array (as output) from the simulink model to the app designer?
  • Is there any way to pass the array from the app designer to the simulink model as inputs and run the simulink model iteratively (inside simulink) to find outputs for each element of the input array then form an output array (inside simulink) and then pass the output array from the model to the app?
  • Is there any way to pass the each element of the array from the app designer to the simulink model as inputs and run the simulink model iteratively (inside app designer) to find outputs for each element of the input array then pass each output value from the simulink model to the app designer and then form an output array (inside app designer)?
P.S. I am just a beginner, I don't know how to use handle (I don't even exactly know what it is) and bus structures.
Best regards

Risposte (1)

Pujitha Narra
Pujitha Narra il 14 Nov 2019
Modificato: Pujitha Narra il 14 Nov 2019
Hi Nayif,
I would like to answer the 3rd and 4th questions first. Assuming there is no dependency between the ‘iterations’, there is no requirement for a loop! You can conveniently pass an array and Simulink would process it as if it is a single unit and give you the output array (without us taking the pains of passing each element or running the model for each element)
There are many ways to pass an array from an app to a Simulink model and vice-versa. One of the ways to do it, is to use the ‘From Workspace’ block in your model. They let you use data from the workspace. This is how you can use it:
  1. Input an array from the app to the Simulink model:
Use the callback function to store the input array in the workspace. The function ‘assignin’ is of use here.
Use the ‘From Workspace’ block in the model to use the array, now stored in the workspace.
Note: Append the timestamp at the beginning. For instance, if the input array is [10,12,9,3], then the input to the Simulink model should be [0,10,12,9,3].
The following links might be of help:
2. Output of the simulation to the app:
Use the ‘sim’ to simulate the model from the callback itself and the store the output, say out. Now, out.simout.Data would contain your output array.
The following links might be of help:
Note: The output would be generated at each step of the execution. You can play with the step size of the execution by changing the Solver settings which you can find at Modelling>Model Settings>Solver.

Categorie

Scopri di più su Model References in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by