Why does PostSimFcn keeps throwing errors when running Parsim?

12 views (last 30 days)
Hi,
I'm trying to use Parsim to run a lot of simulations. Since the logged data volume is huge, I wanted to use the PostSimFcn to process the data and only return the mean values after each run.
I set up the function in SimulationInput objects used by Parsim as shown below:
tmpin = tmpin.setPostSimFcn(@(x) postsim(x));
function newout = postsim(out)
timing_signal = out.logsout{1}.Values.Time;
power_signal = out.logsout{1}.Values.Data;
avg = trapz(timing_signal,power_signal)/180;
newout.mean = avg;
newout.p2a = max(abs(power_signal))/avg;
end
Then it throws me errors "Error executing 'PostSimFcn' on SimulationInput object. Caused by: brace indexing is not supported for variables of this type"
I then changed the code to:
function newout = postsim(out)
timing_signal = out.yout.get('power').Values.Time;
power_signal = out.yout.get('power').Values.Data;
avg = trapz(timing_signal,power_signal)/180;
newout.mean = avg;
newout.p2a = max(abs(power_signal))/avg;
end
It throws me errors "Error executing 'PostSimFcn' on SimulationInput object. Caused by: dot indexing is not supported for variables of this type"
Then I changed the simulink file to directly set an outport at the root level and changed the code to:
function newout = postsim(out)
timing_signal = out.tout;
power_signal = out.yout;
avg = trapz(timing_signal,power_signal)/180;
newout.mean = avg;
newout.p2a = max(abs(power_signal))/avg;
end
It throws me errors "Error executing 'PostSimFcn' on SimulationInput object. Caused by: X must be a vector"
I searched around the Internet and it seems nobody has mentioned this problem and the matlab documentation for setPostSimFcn doesn't mention anything but the "out" argument for the function is the copy of the SimulationOutput object. https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setpostsimfcn.html
I'm running on a linux machine with Matlab 2020a.
Can anyone provide some tips on what may be going wrong? Thanks advance
  3 Comments
Rahul Kumar
Rahul Kumar on 8 Apr 2022
Try running in serial
out = sim(tmpin)
Put a breakpoint in the postsim function so you can debug the issue.
Lisheng Yang
Lisheng Yang on 8 Apr 2022
That's a good point! Actually the problem is there are errors in the simulation and the SimulationOutput object doesn't contain the normal outputs, which leads to this error message.

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Performance 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!