convert m file into simulink model

2 views (last 30 days)
hong yang
hong yang on 31 Aug 2015
Commented: Walter Roberson on 31 Aug 2015
Hallo everyone!
I want to convert a m file into simulink model, which will be later connected with Digsilent Power Factory.I chose matlab funtion.
treeensmeble is a struct and I have already saved it as a mat file. It has two feild in treeensemble, I just use one "trees". I want to load it into the funtion. But there is an error: Undefined function or variable 'treeensemble'.
The code is as below:
function [YTS]=rtenspred(XTSA)
coder.extrinsic('load')
load treeensemble
verbose=0;
persistent XTS;
persistent tree;
XTS=XTSA;
Nts=size(XTS,1);
T=length(treeensemble.trees);
YTS=0;
for t=1:T
if (verbose)
fprintf('t=%d\n',t);
end
tree=treeensemble.trees(t);
YTS=YTS+tree.weight*rtpred();
end

Answers (1)

Walter Roberson
Walter Roberson on 31 Aug 2015
data = load('treeensemble.mat');
treeensemble = data.treeensemble;
  2 Comments
hong yang
hong yang on 31 Aug 2015
Thanks for your answer. But when I use this code, it seems still be an error as below:
Attempt to extract field 'treeensemble' from 'mxArray'.
Is this a problem with struct type variable?
Walter Roberson
Walter Roberson on 31 Aug 2015
I think to fix this, you are going to first assign treeensemble a struct() . I do not know if
treeensemble = struct();
will be enough, or if you will need to assign it with all of the fields, something like
treeensemble = struct('trees', [], 'weights', []);

Sign in to comment.

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!