struct initialization in Embedded Matlab (R2008B)

11 vues (au cours des 30 derniers jours)
Guy Rigot
Guy Rigot le 22 Juil 2015
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

Réponses (0)

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by