How to resolve this error "Code generation does not support mxArrays inside cell arrays"

49 Ansichten (letzte 30 Tage)
Hi I am trying to use 3rd part toolboxes provided by Cantera to simulated constant volume combustion through matlab simulink.
I am able to run cantera toolboxes and codes through matlab. But when I am trying to run through simulink it gives errors. I have attached the error picture. I have used coder.extrinsic command while using cantera functions. I have tried to search for the same. One of the solution I found was to write S function but don't know how it will work. Any help would be appreciated.
function reactor2(g)
% REACTOR2 Zero-dimensional kinetics: adiabatic, constant volume.
%
% This example illustrates how to use class 'Reactor' for
% zero-dimensional kinetics simulations. Here the parameters are
% set so that the reactor is adiabatic and constant volume.
%
help reactor2
if nargin == 1
gas = g;
else
gas = GRI30;
end
nsp = nSpecies(gas);
% set the initial conditions
set(gas,'T',1001.0,'P',oneatm,'X','H2:2,O2:1,N2:4');
% create a reactor, and insert the gas
r = IdealGasReactor(gas);
% create a reactor network and insert the reactor
network = ReactorNet({r});
t = 0;
dt = 1.0e-5;
t0 = cputime;
for n = 1:100
t = t + dt;
advance(network, t);
tim(n) = time(network);
temp(n) = temperature(r);
x(n,1:3) = moleFraction(gas,{'OH','H','H2'});
end
disp(['CPU time = ' num2str(cputime - t0)]);
clf;
subplot(2,2,1);
plot(tim,temp);
xlabel('Time (s)');
ylabel('Temperature (K)');
subplot(2,2,2)
plot(tim,x(:,1));
xlabel('Time (s)');
ylabel('OH Mole Fraction (K)');
subplot(2,2,3)
plot(tim,x(:,2));
xlabel('Time (s)');
ylabel('H Mole Fraction (K)');
subplot(2,2,4)
plot(tim,x(:,3));
xlabel('Time (s)');
ylabel('H2 Mole Fraction (K)');
clear all
cleanup
  1 Kommentar
Roberto Paolinelli.
Roberto Paolinelli. am 8 Nov. 2021
Hello Prasad,
I have similar problem as you...
I'm trying to run Cantera in Simulink with matlab.system objects and converting some classes to classdef for harware in the loop purposes (I'm not using Interpreted Execution).
Anyway I get the following error :
'Code generation does not support tunable class properties of mxArray type.'.
This happens to me when cantera is invoking ctmethod appearing a mexw64.
How did you manage your problem?
Thank you very much
Roberto Paolinelli

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sukrut Tamhankar
Sukrut Tamhankar am 8 Mai 2020
Cell arrays cannot contain mxarrays. In a cell array, you cannot store a value that an extrinsic function returns. This is one of the limitations of cell array for code generation.
The following MATLAB documentation link refers to cell array limitations for code generation:
The following MATLAB documentation sections may help to get more information regarding S-Functions:
  1. What is an S-function
  2. When to use an S-function
  3. S-Functions and code generation
  4. S-Function features and limitations
  1 Kommentar
Walter Roberson
Walter Roberson am 8 Mai 2020
I suspect the way to proceed would be to insert
r = zeros(APPROPRIATE_SIZE_GOES_HERE);
right before
r = IdealGasReactor(gas);
That would tell the compiler that the results of the call to IdealGasReactor are to be written into the local array r, after which you can include that local array inside a cell array.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu LEGO MINDSTORMS EV3 Hardware finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by