Is it possible to create a Simulink model from my code?
조회 수: 2 (최근 30일)
이전 댓글 표시
I am new to Matlab and Simulink and i just created some code in Matlab and i tried to do the same thing in Simulink but i was not able to complete it. I was not able to reproduce the system by only using Simulink blocks because i did not find any possibility to get access to the data for the temperatures in previous timesteps. I also tried to use the Simulink function block but it did not work as well because i was not able to get an vector as output.
clear all
% Constants
roh_w = 983.2;
cp_w = 4183;
lambda_w = 0.6544;
dt = 2.5;
m_strom = 1;
r = 0.5;
h = 2.5;
Tanklayers = 60;
Timesteps = 1440;
T_Start = 80;
T_in = 50;
A_Tank = pi*r^2;
h_layer = h/Tanklayers;
v_w = m_strom/(roh_w*A_Tank);
CFL = (v_w*dt)/h_layer;
Fo = (lambda_w*dt)/(roh_w*cp_w*h_layer^2);
T = zeros(Tanklayers,1);
T_store = zeros(Tanklayers,Timesteps);
% Calculating the temperature in the tank
for x = 1 : Timesteps
T_old = T;
if x == 1
for y = 1 : Tanklayers
T(y) = 80;
end
else
for y = 1 : Tanklayers
if y == 1
T(y) = (Fo + CFL)*T_in + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y+1);
elseif y == Tanklayers
T(y) = (Fo + CFL)*T_old(y-1) + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y);
else
T(y) = (Fo + CFL)*T_old(y-1) + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y+1);
end
end
T_store(:,x) = T;
end
end
figure
plot(T_store(50,:))
hold on
ylabel("Temperatur [°C]")
xlabel("Timestep")
댓글 수: 0
채택된 답변
Sarthak
2023년 2월 21일
Hi Lars,
As mentioned, you tried using the function block but could not get a vector as an output. I believe you have not made the appropriate changes to your function code. The MATLAB function should have the correct input and output variable with the correct return type. If you return a vector, you will get a vector as an output. You can use the DEMUX block to segregate the variables.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!