Importing .m code into simulink

19 views (last 30 days)
Wely Verhemel
Wely Verhemel on 7 Aug 2012
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.

Answers (2)

TAB
TAB on 7 Aug 2012
Edited: TAB on 8 Aug 2012
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 Comment
Kaustubha Govind
Kaustubha Govind on 7 Aug 2012
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.

Sign in to comment.


Muruganandham Subramanian
Edited: Walter Roberson on 10 Aug 2012
Hi,
You can use Matlabfcn block in simulink.

Tags

Products

Community Treasure Hunt

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

Start Hunting!