How can I use a variable load power in my simulink which is changing every second?

조회 수: 32 (최근 30일)
Hello everyone,
I am using a daily power consumption of a house in my model in simulink, which is an excel file with 2 Columns. the 1st one is for seconds and the 2nd one is for the value of the power at this time.
I am trying to use it in my simulink but I always get an error because the active load power can not be changed while the simulation is running.
so How can I make my power changes every second in my simulation scope while my model is running?
I have used a variable resistor but it didn not work.
Thanks in advance.

답변 (1개)

Anurag Ojha
Anurag Ojha 2023년 8월 8일
Hello Omar,
As per my understanding you're trying to simulate a dynamic variable load power profile in Simulink based on the data from an Excel file. You're correct that we cannot directly change simulation parameters, such as load power, while the simulation is running. However, there are ways to achieve your goal. Here's one workaround:
Using a MATLAB Function Block:
We can use a MATLAB Function block in Simulink to read the Excel file and provide the changing load power values to simulation.
You can follow these steps:
  • Read Excel Data: Use the MATLAB Function block to read the Excel file and extract the load power data. We can use the “readtable function to read the data from the Excel file.
  • Interpolate Data: Since the data is provided at second intervals, We can interpolate the data to get load power values for each simulation time step. MATLAB provides functions like interp1 for interpolation.
  • Output Load Power: Output the interpolated load power values from the MATLAB Function block.
  • Sample Time: Set the sample time of the MATLAB Function block to match your simulation time step (e.g., 1 second).
  • Simulate: Run your simulation, and the load power values will change every second based on the data from the Excel file.
Take care of the cases where the simulation time exceeds the range of your Excel data. Here's a example of what the MATLAB Function block code might look like:
function loadPower = fcn(time)
% Load data from Excel file
excelData = readtable('power_data.xlsx');
% Extract time and load power columns
excelTime = excelData(:, 1);
powerValues = excelData(:, 2);
% Interpolate load power values
loadPower = interp1(excelTime, powerValues, time, 'linear', 'extrap');
end
You can refer to following MATLAB documentation to explore more:
Hope it helps!

커뮤니티

더 많은 답변 보기:  Power Electronics Community

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by