Why is Stateflow producing an error when writing an array of buses with a string type
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Gowtham
2023-12-27
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!