I have problems reading values from a Python dictionary in to Simulink using a Matlab Function Block. The Python Dictionary is stored in the Matlab Base Workspace. It contains Data delivered by a MQTT-Broker. The keys of the dicitonary are the topics and the values are the payload of specific MQTT-Messages. Because all of the topics contain slashes it is not possible to convert the Python-Dictionary to a Matlab struct. Now I want to read the values of defined topics to my Simulink Model. Unfortunately the syntax that works in Matlab doesn't work in the Simulink Matlab Function Block.
In Matlab I am able to read data from the dictionary by using the key in curly brackets:
MQTTValue = PythonDict{'level1/level2/value'}
To read the payload of the same MQTT-Message to Simulink i used the following code in a Matlab Function Block:
function MQTTValue = fcn()
coder.extrinsic('evalin');
PythonDict = evalin('base','PythonDict');
MQTTValue = PythonDict{'level1/level2/value'};
However I get the following error when running the Model:
Brace indexing is not supported for variables of this type.
I expected to be able to read the value from the dictionary just like in Matlab.
Also when trying to read multiple entries of the dictionary using a cell-Array called TopicArray and the following code Matlab crashes completely during the compilation of the model:
function MQTTValues = fcn(TopicArray)
coder.extrinsic('evalin');
MQTTValues = zeros(1,length(TopicArray));
PythonDict = evalin('base','PythonDict');
for i = 1:length(MQTTValues)
MQTTValues(i) = PythonDict{TopicArray{i}};