Why is Stateflow producing an error when writing an array of buses with a string type
1 view (last 30 days)
Show older comments
I'm currently building a stateflow model in order to convert a m-script based matlab function to have some sort of graphical representation to promote readability.
In doing so I'm getting an error at the first block stating that I have a variable that "contains and array of bus type with a string type element and is only support for read-only input data in this block."
This is entirely true as I am creating an array of buses and one element in the bus is a string type containing the name of the bus. This is done intentionally as this bus creates the parameters for a camera that I will be using in a scene later and I want to be able to incorporate as many cameras in the scene as I'd like (in this case just 2).
The variable in question is created by a script I'm running with coder.extrinsic and this script works perfectly acceptable in the standard Matlab workspace.
*I've added images as attachements for reference*
Looking through the documentation is looks like both simulink and stateflow support strings with no exception like this, so I would think this should work.
I don't know if this is an issue with the string, the string in the bus, or the bus in the array. I am open to different solutions and eleminating the string as long as I can reference my buses consistently and programmatically (converting a bus to a struct in code and then calling fields by name seems to work nicely in the workspace).
Any help on trying to understand what is going on and how I could either fix it or create a workaround would be greatly appreciated.
0 Comments
Accepted Answer
Gowtham
on 27 Dec 2023
Hello Joe,
I understand that you are trying to build a Stateflow model which converts the m-script based MATLAB function to a graphical representation and facing errors related to data which has an array of bus type with a string type element.
To resolve this issue, a possible workaround is to restructure the 'Import_Scene_Data()' function. This modification would involve having the function output individual arrays corresponding to the fields of 'Camera_Def', rather than the bus array itself. These separate arrays could then be utilized as needed within your model.
For a sample demonstration of the above process, kindly refer to the following code snippet:
function [Camera_Pos, Camera_Dim, Camera_FPS, Camera_iFov, Scene_Def, Object_Def] = Import_Scene_Data()
% Your existing logic to import data...
% Initialize arrays based on the size of Camera_Def
numCameras = size(Camera_Def, 1);
Camera_Pos = zeros(numCameras, 3); % For Position_X, Position_Y, Position_Z
Camera_Dim = zeros(numCameras, 2); % For X_Dim, Y_Dim
Camera_FPS = zeros(numCameras, 1); % For FPS
Camera_iFov = zeros(numCameras, 1); % For iFov
% Populate arrays with data from Camera_Def
for i = 1:numCameras
Camera_Pos(i, :) = [Camera_Def(i).Position_X, Camera_Def(i).Position_Y, Camera_Def(i).Position_Z];
Camera_Dim(i, :) = [Camera_Def(i).X_Dim, Camera_Def(i).Y_Dim];
Camera_FPS(i) = Camera_Def(i).FPS;
Camera_iFov(i) = Camera_Def(i).iFov;
end
end
Kindly refer to the following MathWorks Documentation(s) for further information on how to use Simulink Bus Signals https://www.mathworks.com/help/simulink/slref/simulink-bus-signals.html
Hope this helps.
Best Regards,
Gowtham
0 Comments
More Answers (0)
See Also
Categories
Find more on Simulink Functions 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!