Matlab Function block in Simulink-Error-cell() constructor is not supported for code generation

1 次查看(过去 30 天)
When I use matlab function block in Simulink. I use another matlab function which contains cell type. But simulink reported error message because of cell. How to avoid this? I'm kind of don't want modify the function because all my functions have cell it's a lot of work to modify them all.
Error message: Simulation 28 Clear Save 11:26:28 PM Nov 27, 2014 Elapsed: 7 sec
cell() constructor is not supported for code generation
Function 'RealCo.m' (#56.102.111), line 5, column 4: "cell(9,1)" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Below is the function I called in Matlab Function block in Simulink, Simulink encounter error right in the 5th line.
function Co=RealCo(q)
l=60;
%%%Coordinate Calculation
%Guess value adopt the unique position below
*Co=cell(9,1);*
for i=1
Co{i}=[0;0;0];
end
Co{1}=[sqrt(3)*l/4;0;0];
Co{2}(1)=-sqrt(3)*l/4;
Co{2}(2)=l/2;
Co{2}(3)=0;
Co{3}(1)=Co{2}(1);
Co{3}(2)=-l/2;
Co{3}(3)=0;
Co{4}=[sqrt(3)*l/4;-l/2;sqrt(3)*l/2];
Co{5}=Co{4};
Co{5}(2)=-Co{5}(2);
Co{6}=Co{4};
Co{6}(1)=-Co{6}(1);
Co{6}(2)=0;
for i=7:9
Co{i}=Co{i-6};
Co{i}(3)=sqrt(3)*l;
end
guess=zeros(27,1);
for i=1:3:27
%When i=1,j=1 i=4,j=2 i=7,j=3 ...
j=(i-rem(i,3))/3+1;
guess(i)=Co{j}(1);
guess(i+1)=Co{j}(2);
guess(i+2)=Co{j}(3);
end
%Use fsolve to solve the system based on current value of q
fC=@(R)Coor(R,q);
[result, fval, exit, output]=fsolve(fC,guess);
% result
% fval
% eqns(guess)
% output
for i=1:3:27
%When i=1,j=1 i=4,j=2 i=7,j=3 ...
j=(i-rem(i,3))/3+1;
Co{j}=[result(i);result(i+1);result(i+2)];
end

回答(1 个)

Orion
Orion 2014-11-28
编辑:Orion 2014-11-28
HI,
Cell arrays are not supported for code generation.
You're gonna have to rewrite your algorithm using matrix/vectors.
Note also that handles of functions are not always supported ( fsolve and fC=@(R)Coor(R,q);)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by