Is there a way to use external matlab struct variables and object variables in simulink matlab function block ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dear all,
I am trying to implement a simulink matlab function, that has to use only those input arguments required for the function. However, I have few extra struct and object type parameters that are to be used for complete execution of my function.
for e.g. I have a svmpredict function to be called within this matlab function which use a structure variable as one of the argument. I also have neural network net function or sim function to be used within this simulink function block, which also uses a class object variable.
at the end of this question i have posted my code snippet for reference what is not clear to me is, how can i make these workspace objects available within my simulink function block without explicitly passing as argument ? I really hope there is a way to make this happen, i kindly require your assistance in this regard.
Any help is appreciated and Thanks.
function y = fcn(SOC,Qd,Tamb,Batt_Cap,switch_in)
%#codegen
coder.extrinsic('svmpredict','net','polyvaln')
Cd = Qd*Batt_Cap;%Batt_Cap in Ah
soc_test = SOC;
current = Cd*ones(1,length(soc_test));
temp = Tamb*ones(1,length(soc_test));
dv = 0.0005*ones(1,length(soc_test));
soc_testn = mapminmax('apply',soc_test,pssoc);
tempn = mapminmax('apply',temp,pstemp);
currentn = mapminmax('apply',current,pscur);
xtestn = [soc_testn',currentn',tempn',dv'];
xtest = [soc_test',current',temp'];
y = 1*ones(length(soc_test),1);
switch switch_in
case 1
%'model' is the output structure of svmtrain and svmpredict is
%external function
[estimate_out, Acc, projection] = svmpredict(y,xtestn, model);
case 2
%function net uses an object named 'net' which is ouput of the
%neural net training
[estimate_out] = net(xtest');
case 3
%function polyvaln uses an external struct parameter 'poly_mdl'
% as input
[estimate_out] = polyvaln(poly_mdl,xtest);
case 4
disp('positive number');
otherwise
disp('Please use numbers between 1, 2, or 3 for selection');
error('myApp:argChk', 'Wrong choice selection for static model selection')
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!