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
编辑:Walter Roberson 2012-8-10
Hi,
You can use Matlabfcn block in simulink.

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by