如何把matlab里面编译的脚本文件运用到simulink里面去,不会啊,求大神解答
转存格式,具体看是什么样式的格式文件了。
我想在的问题是想把一个包含了三个funtion的程序转换成simulink中运行,因为之后要与Powerfactory一起运行。这三个函数之间有调用关系。
之前想用matlab function,但是他直接忽略了后两个函数,不太想用s-function,不知道各位大神有什么好的建议吗。
m函数如下:
function [YTS]=rtenspred(treeensemble,XTSA)
% inputs:
% tree: a tree output by the function rtenslearn_c
% XTS: inputs for the test cases
% YLS: outputs for the learning sample cases
% Output:
% YTS: Predictions for the test cases
verbose=0;
global XTS;
global 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
function [YTS]=rtpred()
% inputs:
% tree: a tree output by the function rtenslearn_c
% YLS: outputs for the learning sample cases
% XTS: inputs for the test cases
% Output:
% YTS: output predictions for the test cases
global assignednodets
global XTS
global tree
Nts=size(XTS,1);
assignednodets=zeros(Nts,1);
verbose=0;
YTS=zeros(Nts,size(tree.predictions,2));
if (verbose)
fprintf('computation of indexes\n');
end
getleafts(1,1:Nts);
if (verbose)
fprintf('computation of predictions\n');
end
for i=1:Nts
YTS=tree.predictions(tree.indexprediction(assignednodets),:);
end
function getleafts(currentnode,currentrows)
global assignednodets
global XTS
global tree
testattribute=tree.testattribute(currentnode);
if testattribute==0 % a leaf
assignednodets(currentrows)=currentnode;
else
testthreshold=tree.testthreshold(currentnode);
leftind=(XTS(currentrows,testattribute)<testthreshold);
rightind=~leftind;
getleafts(tree.children(currentnode,1),currentrows(leftind));
getleafts(tree.children(currentnode,2),currentrows(rightind));
end
层次设计, 顶层一个函数,再嵌套