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
编辑: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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by