Importing .m code into simulink

조회 수: 5 (최근 30일)
Wely Verhemel
Wely Verhemel 2012년 8월 7일
Dear Matlab enthusiasts,
I am a beginner into simulink so im trying to understand the basics. I have written a code in the matlab editor. I can get it to work there but i want to use it inside simulink. I have sought for several tutorials on how to import the code but i find them pretty vague as they don't have any good examples. Which steps do i need 2 take care off to get this .m code working inside simulink? My code is quite simple here's a copy of it.
%Simuleert een tegenstroom warmtewisselaar
%Invoer/Input
Tc1=23; %koude medium (degC)
Mc=0.5; %Massastroom koude medium (kg/s)
Cc=1002; % Soortelijke warmte (J/kgK)
Th1=30; %Temperatuur warme medium(degC)
Mh=0.2; %Massastroom hete medium(kg/s)
Ch=4200; %Specifieke warmte (J/kgK)
r=0.005; %Straal van de pijp (m)
U=800; % Warmteoverdrachtscoefficient (W/m2K)
l=8; %lengte van de pijp (m)
%Oplossing
p=((Mh*Ch)/(Mc*Cc));
b=(1-p);
d=(2*pi*r*U*b)/(Mh*Ch);
x=0:0.01:l; % Puntenverdeling in de pijp
N=(100*l)+1; % aantal elementen in de pijp
h1=((Tc1*(exp(d*x)-1))+(Th1*b));
h2=exp(d*x)-p;
for (i=1:N)
Th2(i)=h1(i)/h2(i);% Rij hete fluida
Tc2(i)=Tc1+(p*(Th1-Th2(i)));% Rij koude fluida
end
%Temperatuur plot
figure;
plot(x,Th2,'r');
hold on;
plot(x,Tc2);
title('TSA');
xlabel('Afstand');
ylabel('temperatuur');
grid;
With kind regards.

답변 (2개)

TAB
TAB 2012년 8월 7일
편집: TAB 2012년 8월 8일
Matlab language and simulink are meant for different purpose. Matlab is the programming environment used for analysis, plotting, visualizing the data. While simulink is the toolbox which runs on matlab environment and used for modelling and simulating dynamic systems in graphical way.
In your matlab code you are processing and plotting some data, but simulink is not meants for it. In simulink you can implemnt your logic using blocks and simulate and visualize the algorithm using tools provided in simulink only.
Even though it is possible to use a part matlab language inside the simulink(using matlab function block), but this is not good idea to use matlab graphics function in this block.
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2012년 8월 7일
I agree with TAB, but perhaps you can avoid using the plot commands in the block. Instead, you may output the signal(s) to be plotted from the block and use a Scope block to visualize the signal.

댓글을 달려면 로그인하십시오.


Muruganandham Subramanian
Muruganandham Subramanian 2012년 8월 7일
편집: Walter Roberson 2012년 8월 10일
Hi,
You can use Matlabfcn block in simulink.

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by