How to plot multiple graphs by changing parameters of the model?

6 次查看(过去 30 天)
I am plotting the V-I characteristics of a solar PV module for different temperatures. I have created the model as shown in the figure. Initially the temperature is set to a particular value, say 298K. Then I plot the V-I characteristics using 'To workspace' block and writing plot commands in command window. Then the 'hold on' command is used to hold the figure. Again the temperature is set to a different value. Then the new curve is plotted on the same figure. Is there any simpler way to do this? I have to plot for 6 different temperatures. Also I have to change other parameters of the system and plot P-V characteristics as well. Is there any iterative way to do this?

回答(1 个)

Snehal
Snehal 2025-1-31
Hi,
I understand you are using MATLAB to plot the V-I and P-V characteristics of a solar PV module at various temperatures.
This can be achieved with the help of MATLAB’s ‘set_param’ and ‘sim’ functions.
Refer the below steps to plot curves for changing temperatures:
  1. Define a range of temperatures in an array. Iterate through these stored values using a 'for' loop and change the model parameters with MATLAB's 'set_param' function in each loop.
  2. Use 'sim' function to execute the simulation in each iteration, followed by the ‘simOut.get' function to get the results.
  3. To ensure corresponding curves are plotted on the same plot, use ‘hold on’ inside the ‘for’ loop. When working with numerous figures at the same time, you can also utilize MATLAB's 'figure' function to switch between plots/figures.
Refer to the sample code below:
% Defining the range of temperature values as an array
temperatures = [298, 303, 318, 323];
numTemps = length(temperatures);
% Loop over each temperature
for i = 1:numTemps
% Set the temperature parameter in the workspace
temperature = temperatures(i);
set_param('model_name/Temp', 'Value', 'temperature')
% include code for executing the simulation and storing output values in corresponding variables (say, ‘V’ and ‘I’ in this case) here
% Plotting V-I characteristics
figure(1);
plot(V, I, 'DisplayName', sprintf('Temp = %dK', temperature));
hold on;
% Plotting P-V characteristics
figure(2);
plot(V, V.*I, 'DisplayName', sprintf('Temp = %dK', temperature));
hold on;
end
Similarly, you may create arrays for other changing parameters and loop over them in the same manner you would with the temperature parameter.
Refer to the below documentations for better understanding:
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by