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

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

a possible mix of base workspace and function workspace. In any case, you need to show some example code and model to debug the problem.
I implemented some easier example to show You.
Here is my circuit:
I want to make 10 plots, in everyone amplitude of signal increase in for loop: Here is code example:
for i = 1:10
Amp = i
sim('untitled')
plot(out.simout.time, out.simout.data)
hold on;
end
What I'm getting, is plot with only one sinus that amplitude is 1. What am I doing wrong ?
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

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 Comments

That works ! Thank You a lot. I spent 7 hours, trying to figure out what's wrong. Thank You.
Holy moly what a ride... thanks for this, i also spent some hours on this issue @Wiktor Jachym.
Thanks alot @Fangjun Jiang

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!