As of right now, the only way of doing what I want is to use switch statement, with 261 cases, or however big cell array I have, and statically define what bus element I want to probe in the different cases, the ID number being what decides the case. I just think this is little bit silly way to do it...
Code generatable simulink matlab function for bus probing
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
I have come to dead end when it comes to reading simulink bus in a matlab function block. The idea is to search a given ID number from 2-dimensional cell array (the ID is in the first column of the array) and with the ID's name, extract the corresponding value from the element in the bus (the ID name and bus element name are the same). The rows of the cell array are as such:
{ID SUBID DATATYPE NAME ACCESS DEFAULT} -- all strings
There are 261 unique IDs in the array, and with the function below one should (at least in theory) be able to probe the correct bus element:
function y = fcn(u)
OD = {261x6 cell array of strings};
bus_levels = {"General" "Connected_Packs"};
id = 8252; % This would later on come from outside of the function
signal = "Default name"; % defaults to this bus element
for i = 1:height(OD)
if hex2dec(OD{i}) == id
signal = OD{i,4};
break;
end
end
y = u.(bus_levels{1}).(signal);
end
But as some of you may know matlab will give an error that the variable called signal is not constant. So i was wondering is this a lost cause or is there some way of doing this in such a way that it is code generatable and does not rely on external files or anything else, only what one can do in simulink/matlab. Thank you.
0 comentarios
Respuestas (1)
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!