struct initialization in Embedded Matlab (R2008B)
4 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on String in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!