How to call the function based on the simulink model?
조회 수: 1 (최근 30일)
I have problem with my code - I get error due to multiple causes.
I need three figures- depending on the different values of the Rd and Ud. I want to place my code in the function conected with the simulink model.
What should I modify?
wt=[tp tu tu+10e-12 tpw tpw+10e-12 tk];
wU=[0 0 U U Ud Ud];
wRd=[0 0 0 0 Rd Rd];
figure('name','Wyniki symulacji w funkcji czasu','numberTitle','off');
legend([h1;h2;h3],'Prąd u.l.','Prąd u.nl.','Strumień u.l.','Strumień u.nl.','Energia u.l.','Energia u.nl.');
ylabel('Prąd, A, Strumień, Wb, Energie, J');
figure('name','Przebiegi prądów wyznaczanie czasów zaniku','numberTitle','off');
legend([h1;h2],'Prąd u.l.','Prąd u.nl.','Koniec zaniku u.l.','Koniec zaniku u.nl.');
text(tzn+tpw,0.1*iz,['tzn = ' num2str(tzn,'%0.3f') ' s'],'HorizontalAlignment','left','BackgroundColor',[1 1 1]);
text(tzl+tpw,0.2*iz,['tzl = ' num2str(tzl,'%0.3f') ' s'],'HorizontalAlignment','left','BackgroundColor',[1 1 1]);
ylabel('Prąd, A, ');
Sara Nadeau 2021년 10월 18일
It's a little hard to say without knowing the specific errors you're getting. However - is there a reason you aren't assigning the output of the sim function to a variable? Have you tried updating the call to sim to look like:
out = sim('zad3cw2_sim');
Then, you'd update all your statements that access the output data to use the out variable (or whatever you choose to name it) instead of ans.
추가 답변 (2개)
Walter Roberson 2021년 10월 17일
What should I modify?
You should get rid of the "clear all": it is erasing variables in the base or function workspace that your code is expecting to exist.
You should probably get rid of the "close all" as well, as that might affect scopes or objects drawn by Simulink.
Getting rid of the "clc" would probably be a good idea too.
Paul 2021년 10월 19일
편집: Paul 님. 2021년 10월 19일
Since you're using 2020b, try changing your sim() command to:
out = sim('zad3cw2_sim','SrcWorkspace','current')
This should probably work, but there are some caveats, so I suggest you check the doc page for sim() to see if they apply to your case.
However, SrcWorkspace is not supported for versions later than 2020b. So if you want a solution that works in 2020b and later versions, you can call sim() with a Simulink.SimulationInput object. Take a look at that doc page and then feel free to reply here if you have any questions on how to make that work.
There are other options should neither of these meet your needs. In fact, this question has come up here several times and some searching should quickly find relevant discussions that cover these other options.