converting M.file into simulink
Afficher commentaires plus anciens
Hi;
I already make a program using M.file that simulate the unsteady heat conduction in 1-D by using finite difference method. i've tried the Matlab function block, but failed. Could anyone suggest how to adjust the M.file code
N2=10;
T=zeros(1,N2);
Tn=zeros(1,N2);
for i=1:N2 T(1,i)=100; end
Dx=0.1;
Dt=0.001;
M=2*Dx;
k1=1;
k2=1;
p1=1;
p2=1;
for iter=1:100
for i=1:1
Tn(1,i)=(1-((2*k1*Dt)/(p1*Dx^2)))*(T(1,i)) + ((k1*Dt)/(p1*Dx^2))*(2*T(1,i+1));
end
for i=2:N2-1
Tn(1,i)=(1-((2*k1*Dt)/(p1*Dx^2)))*(T(1,i)) + ((k1*Dt)/(p1*Dx^2))*(T(1,i+1)+T(1,i-1));
end
for i=N2:N2
Tn(1,i)=(1-((2*k2*Dt)/(p2*Dx^2)))*(T(1,i)) + ((k2*Dt)/(p2*Dx^2))*(T(1,i-1)-((2*Dx/k2)*(T(1,i)-25))+T(1,i-1));
end
for i=1:N2
T(1,i)=Tn(1,i);
end
end
Réponses (1)
Azzi Abdelmalek
le 19 Fév 2014
0 votes
You can't use a script with matlab function block. You need to define your input a d output argument to make your code a function.
4 commentaires
Mohd Ibthisham
le 19 Fév 2014
Azzi Abdelmalek
le 19 Fév 2014
To suit the matlab function block, your file should be a function file. You can transform your script file to a function file. The input arguments will be the inputs of your Matlab function block, and the output arguments will be its outputs
You need to know how functions work, look at this link
Mohd Ibthisham
le 19 Fév 2014
Azzi Abdelmalek
le 19 Fév 2014
In Matlab windows command type
mex -setup
Catégories
En savoir plus sur Communications Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!