converting M.file into simulink
Mostra commenti meno recenti
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
Risposte (1)
Azzi Abdelmalek
il 19 Feb 2014
0 voti
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 Commenti
Mohd Ibthisham
il 19 Feb 2014
Azzi Abdelmalek
il 19 Feb 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
il 19 Feb 2014
Azzi Abdelmalek
il 19 Feb 2014
In Matlab windows command type
mex -setup
Categorie
Scopri di più su Communications Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!