How to implement structured data from workspace to matlab function block?

11 vues (au cours des 30 derniers jours)
nabil khalidi
nabil khalidi le 5 Mai 2017
Hello guys, i have written a PV model using Particle Swarm Optimization (PSO) in matlab script, and want to implement it in simulink, the model uses 4 structures to manipulate data, first initiate the 4 structures (each structure contains some scalars and even matrixe and/or arrays), i my own script i initiate them before looping through them until the model converges to a solution (which is the output current). I used initfct callback to initiate all the structured data. which i find in the base workspace and not in the model workspace. which gives an error about structures not defined. any thoughts ?
example of a structure i initiate:
T=struct2array(load('Data1000.mat'));
D.A(1).G=1000;
D.A(1).V=T(:,1);
D.A(1).Ie=T(:,2);
[D.A(1).Pmpp,tmp.mppnindex]=max(T(:,1).*T(:,2));
D.A(1).Vmpp=T(tmp.mppnindex,1);
D.A(1).Impp=T(tmp.mppnindex,2);
D.A(1).Voc=max(T(:,1));
D.A(1).Isc=max(T(:,2));
another more complex
for counter=1:PSO.npop
PSO.pop(counter,1).Rs=zeros(3,1);
PSO.pop(counter,1).Rs(1)=rand*PSO.RsGbest;
PSO.pop(counter,1).Rs(2)=PSO.w*PSO.pop(counter,1).Rs(2)+PSO.C1*rand*(PSO.pop(counter,1).Rs(3)-PSO.pop(counter,1).Rs(1))+PSO.C2*rand*(PSO.RsGbest-PSO.pop(counter,1).Rs(1));
PSO.pop(counter,1).Rp=zeros(3,1);
PSO.pop(counter,1).Rp(1)=rand*PSO.RpGbest;
PSO.pop(counter,1).Rp(2)=PSO.w*PSO.pop(counter,1).Rp(2)+PSO.C1*rand*(PSO.pop(counter,1).Rp(3)-PSO.pop(counter,1).Rp(1))+PSO.C2*rand*(PSO.RpGbest-PSO.pop(counter,1).Rp(1));
PSO.pop(counter,1).A=zeros(3,1);
PSO.pop(counter,1).A(1)=rand*PSO.AGbest;
PSO.pop(counter,1).A(2)=PSO.w*PSO.pop(counter,1).A(2)+PSO.C1*rand*(PSO.pop(counter,1).A(3)-PSO.pop(counter,1).A(1))+PSO.C2*rand*(PSO.AGbest-PSO.pop(counter,1).A(1));
PSO.pop(counter,1).f=zeros(2,1);
PSO.pop(counter,1).f(3)=1;
end
Thank you

Réponses (0)

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by