"Subscripting into an mxArray is not supported" error in Simulink User Defined Function due to 'fieldnames' extrinsic call

1 vue (au cours des 30 derniers jours)
Although I look around the same question on web and see the reasons, I can not find a way to get rid of this error.
I got the error 'Subscripting into an mxArray is not supported' while using Simulink-User Defined Function. My 'extrinsic' call is fieldnames. How can I assign fieldNames(capital 'N', fieldNames=fieldnames(data)) prior to that call? How can I tell the types of fieldNames are strings without subscripting into an mxArray? Because I cannot use fieldNames(i)=...
Note: Or any other suggestion without cell array, fieldname etc? More specifically, I have a .mat file, variable names and their values in it. I will use not only the values, but also their names (strings or char) in my calculations. That is, somehow I should access variable names and values in my Simulink-User Defined Function
function damping = fcn(u)
%#codegen
coder.extrinsic('fieldnames');
coder.extrinsic('length');
coder.extrinsic('cell');
coder.extrinsic('cellstr');
coder.extrinsic('string');
numberOfHydroData = 0;
i = 0;
stateProducts = zeros(10,1);
fieldName = ' ';
for k=1:1:13
for kk=1:1:5
% fieldNames(k,kk)=' '; %if uncomment, will give error
end
end
%%
hydroData = load('data.mat');
hydroData = hydroData.hydroData; % see image below to see how hydroData looks like after implementing this line
numberOfHydroData = length(fieldnames(hydroData))
%% calculation
hydroForces = zeros(6,1);
damping = zeros(6,1);
stateProducts = zeros(int8(numberOfHydroData),1);
fieldNames = cellstr(fieldnames(hydroData));
for i=1:1:numberOfHydroData
fieldNames(i) % just for test below code
% fieldName = char(fieldNames((i))); % if uncomment, will give error
end
% damping = [0;0;0;0;0;0];
damping = hydroForces;
%%
end

Réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by