struct initialization in Embedded Matlab (R2008B)

3 次查看(过去 30 天)
Hi all,
I have a question regarding the initialisation of structs in embedded matlab in R2008B. I have the following example code in an embedded matlab block inside Simulink:
function out = fcn(in)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
persistent states
if(isempty(states))
states=init1();
states=init2(states);
end
out=0
end
function [states] = init1()
states.stat1=0;
end
function [states] = init2(states)
states.stat2=0;
end
This code does not compile and gives me the following error:
"struct {stat1: double} ~= struct {stat1: double, stat2: double}. Structures don't match.
The struct to the left is the class of the left-hand side of the assignment.
Which makes sense, because indeed the two structs are not equal. Replacing the second init function call with:
states.stat2=0
works as expected. I want to do this within a function though... Do any of you know if there is a way of adding fields to the struct from within a function?
Cheers, Guy

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by