- In your App Designer app, create a button or any other UI element that triggers the transfer of the array to the Simulink model.
- In the button's callback function, define the logic to create and populate the variable-length array based on user input or any other source.
- Save the array data to a file (e.g., a text file, MAT file, or CSV file) using MATLAB's file I/O functions. Here is the code for the same.
Using an array created with App Designer in Simulink model
3 views (last 30 days)
Show older comments
I am working on an App Designer standalone app, that parses a CSV file to generate a number array. The array must be used in a Simulink model after the user presses the 'RUN' button.
Since the array is created with the values of the CSV file, the array length is not always the same and this creates a problem because when building the standalone app, the Rapid Accelerator uses the length of the arrays that are defined IN workspace at the time of build.
Because the array created from the CSV and the array IN workspace at the time of build have not the same lengths the simulation results in error.
More specifically, two arrays like mentioned are used for the Data and Breakpoints in a 1-D dimension look-up table
How can I pass a variable length array to the Simulink model from the App Designer?
Tried with the following:
-Using the 'From Workspace' block: which results in error because of the passed array having a different length from the array in the workspace at build time
-Using the 'Inport' block: Not efficient because it requires the data to be timeseries, so the given array itself should be cloned for each time step
0 Comments
Answers (1)
Yatharth
on 26 Sep 2023
Hello Aner,
I understand that you are attempting to import an array from a CSV file using a GUI created with AppDesigner, and you want to transfer this array to Simulink. However, you are encountering an issue with the "From Workspace" block because the array was saved to the workspace before the app was built, and it cannot be overwritten once the app is built and becomes standalone.
Now that the app is standalone, it is no longer connected to the MATLAB Base Workspace. To communicate the array data to a Simulink model, you can utilize inter-process communication methods like Inter-Process Communication (IPC) or External Mode.
Here's an approach you can follow:
function ButtonPushed(app, event)
% Generate a random number for array size
arraySize = randi([6, 8]);
t = (1: arraySize);
% Generate an array of random integers
v = randi([-100, 100], 1, arraySize);
myArray = [t;v];
% your data must be a 2-D array or a timeseries object for Simulink
% to read the data from "From File" block
save('arrayData.mat', 'myArray','-v7.3');
end
4. In your Simulink model, use a suitable block (e.g., "From File" block) to read the array data from the file.
5. Connect the output of the block to the desired part of your Simulink model for further processing.
6.Build the standalone app using MATLAB's App Compiler or other suitable deployment methods to create an executable file.
7. Run the standalone app, and when the button is clicked, it will save the array data to the file.
Note: Make sure to run the standalone app in the same working directory so that simulink can read the new "arrayData" file that is being saved.
I hope this helps.
Regards
Yatharth Taneja
0 Comments
See Also
Categories
Find more on System Composer 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!