converting M.file into simulink
显示 更早的评论
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
回答(1 个)
Azzi Abdelmalek
2014-2-19
0 个投票
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 个评论
Mohd Ibthisham
2014-2-19
Azzi Abdelmalek
2014-2-19
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
2014-2-19
Azzi Abdelmalek
2014-2-19
In Matlab windows command type
mex -setup
类别
在 帮助中心 和 File Exchange 中查找有关 Communications Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!