struct initialization in Embedded Matlab (R2008B)

1 回表示 (過去 30 日間)
Guy Rigot
Guy Rigot 2015 年 7 月 22 日
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 Center および File ExchangeEvent Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by