My simulink model seems to not receiving proper variables from workspace or not returning proper value to workspace.

18 ビュー (過去 30 日間)
I have following problem. I made simulink model, it's simple AC-DC rectifier. Everything works proper until I want to do some research how various value of inductance affects current. I implemented a script, that changes value of inductance in for loop. These values are changing properly because I tested it. After change of inductance value, I'm executing simulink model by function sim() and then I want to get info about current from simulink model, plot it to figure and go to next value of inductance. Instead of this, I'm getting exact values. I was tried to save workspace variables to separated files, and I realised, these values was always the same. So, my question is, how to save data from simulink model with various values of inductance.
  4 件のコメント
Wiktor Jachym
Wiktor Jachym 2020 年 11 月 13 日
of course, aplitude parameter in simulink model is 'Amp'
Wiktor Jachym
Wiktor Jachym 2020 年 11 月 13 日
編集済み: Wiktor Jachym 2020 年 11 月 13 日
What comes to my head, is that Matlab doesn't executing simulink model. I changed code, by adding 'clear' as a last line in the loop, loop ran 1 time properly and then I got error 'Unable to resolve the name out.simout.time.'. Looks like function 'sim(untitled)' did not run in 2nd iteration of loop. But why ?

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 11 月 13 日
I am trying to find the document link but could't. I thought it was in "doc sim".
The problem could be explained by the way sim() is called in the script. Imagine it takes a long time for the model to finish one simulation, the for-loop is not going to wait for the finish of sim() line and then execute the next line. It is just going to issue the sim() command and then moves on to the next loop.
If you gives a return variable to sim() line, it is going to force it to finish and log the return variable. You then can have the expected results.
for i = 1:5
Amp = i
a=sim('untitled')
plot(a.simout.time, a.simout.signals.values)
hold on;
end
  2 件のコメント
Wiktor Jachym
Wiktor Jachym 2020 年 11 月 13 日
That works ! Thank You a lot. I spent 7 hours, trying to figure out what's wrong. Thank You.
Carsten Prokopp
Carsten Prokopp 2021 年 1 月 24 日
Holy moly what a ride... thanks for this, i also spent some hours on this issue @Wiktor Jachym.
Thanks alot @Fangjun Jiang

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by