Matlab Functiion Block in Simulink.
Ältere Kommentare anzeigen
I have a MATLAB function in my Simulink simulation. This Matlab-Function runs in its entirety at every sampling interval. There is a for-loop in this function, which runs from 1:27 at every sampling interval.
I have to log values of (g1 g2 g gopt eopt at line 42, 43, 44, 47, 48) at every iteration but I can only get these vales at the end of the loop when MATLAB-function outputs a value.
For example if simulation is run for 1 sec and sampling time is 0.1 sec then for-loop would run 10 times and total number of iterations will be 270 (27x10), so I need to log vales of above parameters at 270 instances.
I have tried using timeseries() but MATLAB-Function in simulink does not support Code Generation so timeseries() does not work.
Please give ideas on how to approach this problem
I have tried to eliminate MATLAB_Function altogether, and I have converted most of the code to simulink blocks but I am not able to understand/use IF block (to replace if statement at line 46 to 49) in Simulink.
function [Sopt, gee] =MC_control(I_ref,Io,Ve,Is,Vs)
global A Ts R L Aq11 Aq12 Aq21 Aq22 Bq11 Bq12 Bq21 Bq22 S counter
Irefalpha = 2*(I_ref(1) - 0.5*I_ref(2) - 0.5*I_ref(3))/3;
Irefbeta = 2*(sqrt(3)*I_ref(2)*0.5 - sqrt(3)*I_ref(3)*0.5)/3;
gopt = 10000000000;
for k= 1:27;
Ie = S(:,:,k)*Io;
Is_p_3f = Aq21*Ve + Aq22*Is + Bq21*Vs + Bq22*Ie;
Is_p_re = 2*(Is_p_3f(1) - 0.5*Is_p_3f(2)- 0.5*Is_p_3f(3))/3;
Is_p_im = 2*(sqrt(3)*Is_p_3f(2)*0.5- sqrt(3)*Is_p_3f(3)*0.5)/3;
VxN = S(:,:,k)*Ve;
Vo=[0;0;0];
Vo(1) = VxN(1) -(VxN(1) + VxN(2) + VxN(3))/3;
Vo(2) = VxN(2) -(VxN(1) + VxN(2) + VxN(3))/3;
Vo(3) = VxN(3) -(VxN(1) + VxN(2) + VxN(3))/3;
Io_p_3f = (1 - R*Ts/L)*Io + (Ts/L)*Vo;
Io_p_re = 2*(Io_p_3f(1) - 0.5*Io_p_3f(2)- 0.5*Io_p_3f(3))/3;
Io_p_im = 2*(sqrt(3)*Io_p_3f(2)*0.5- sqrt(3)*Io_p_3f(3)*0.5)/3;
Vs_p_3f = Vs;
Vs_p_re = 2*(Vs_p_3f(1) - 0.5*Vs_p_3f(2)- 0.5*Vs_p_3f(3))/3;
Vs_p_im = 2*(sqrt(3)*Vs_p_3f(2)*0.5- sqrt(3)*Vs_p_3f(3)*0.5)/3;
g1 = (abs(Irefalpha - Io_p_re) + abs(Irefbeta-Io_p_im));
g2= abs(Vs_p_re*Is_p_im - Vs_p_im*Is_p_re);
g = g1 + A*g2;
if (g<gopt)
gopt = g;
eopt = k;
end
end
%=============================
SAa = S(1,1,eopt);
SBa = S(1,2,eopt) ;
SCa = S(1,3,eopt);
SAb = S(2,1,eopt);
SBb = S(2,2,eopt);
SCb = S(2,3,eopt);
SAc = S(3,1,eopt);
SBc = S(3,2,eopt);
SCc = S(3,3,eopt);
Sopt = [SAa SBa SCa SAb SBb SCb SAc SBc SCc];
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Naming Conventions finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!