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

25 views (last 30 days)
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 Comments
Wiktor Jachym
Wiktor Jachym on 13 Nov 2020
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 ?

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 13 Nov 2020
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

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!