%% Calculate Dissipated Power Losses Using Specific Interval Widths
% This example shows how to calculate losses based on the power dissipated and return the time series data for a specific time period with averaging applied over intervals of a specified width.
% Open the model. At the MATLAB® command prompt, enter:

model = 'ee_solar_converter'; 
open_system(model) 

% This example model has data logging enabled. Run the simulation and create the simulation log variable.

sim(model) 

% The simulation log variable simlog_ee_solar_converter is saved in your current workspace.
% The model simulation time (t) is 1/60 seconds. Calculate the average dissipated power losses for 1.1e-4 s intervals and return the time series data in cell array for the period when simulation time, t, is 0.008–0.017 seconds.

lossesCell = ee_getPowerLossTimeSeries(simlog_ee_solar_converter...
    ,0.008,0.016,1.1e-4)

% View the time series data. From the workspace, open the lossesCell cell array, then open the numeric array for ee_solar_converter.Diode1.
% The first two columns contain the interval start and end time. The third column contains the power loss data. In this case, to use averaging intervals that are equal in width to 1.1e-4 seconds, the function adjusts the start time for the first interval from the specified value of 0.008 seconds to a value of 0.0081 seconds. There are 72 intervals of 1.1e-4 seconds.
% Plot the data.

plot(lossesCell{1, 2}(:,end))
title('Dissipated Power')
xlabel('Time Interval')
ylabel('Power (W)')

% Copyright 2018 The MathWorks, Inc.