how to simulate a model inside an embedded matlab function block with code have a for loop ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
the block "ERROR LOOP" has a 15 i/p arguments which some are i/p to the block "OFF DESIGN MODULE" which all are sub of ('EngineModel1') i wrote the code for the embedded matlab function in ERROR LOOP block as shown with no syntax errors but when run simulation give an 2 error: as attached.
<<
if true
function yout=ERRORLOOP (VB,V7,V6,V5,V4,V3,V2,V1,E1,E7,E2,E3,E4,E5,E6)
for VB=(0.7:0.02:1.1)
TOLL =0.003;
DELTA=0.005;
ER=[E1;E2;E3;E4;E5;E6;E7];
V=[V1;V2;V3;V4;V5;V6;V7];
ERB=ones(7,1);
DV=ones(7,1);
for z=1:7;
if abs(ER(z)) > TOLL;
for w=1:7;
ERB(w)=ER(w);
DV(w)=DELTA*V(w);
end
for j=1:7;
V(j)=V(j)+DV(j);
sim('EngineModel1');
EMAT=ones(7,7);
AMAT=ones(7,1);
for i= 1:7;
EMAT(i,j)=(ER(i)-ERB(i)/DV(j));
AMAT(i)=-ERB(i);
end
V(j)=V(j)-DV(j);
end
DV(j)=AMAT(i)/(EMAT(i,j));
V(j)=V(j)+DV(j)*0.25;
sim('EngineModel1');
else
end
end
end
yout=[V VB]; end
<<
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148750/image.jpeg)
>>
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148751/image.jpeg)
>>
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148754/image.jpeg)
note: in code i have to simulate the model 'EngineModel1' inside the for loop "j" 7 times and one time after the if condition finished "z"(i.e 8 times each if condition).
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing 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!