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
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
Mohd Ibthisham 2014년 2월 19일
so that means i need to generate a new code that feasible to be use in simulink?i thought there is a way, which slightly adjust the m.file to suit the matlab funtion block
Azzi Abdelmalek
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
Mohd Ibthisham 2014년 2월 19일
I have already transformed the M.file to a function file, but i couldnt manage to do it properly. There is an error 'Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks.Use 'mex -setup' to select a supported C-compiler'. Anyway thanks for kind assistance i will look through the matlab-function documents.
In Matlab windows command type
mex -setup

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Communications Toolbox에 대해 자세히 알아보기

질문:

2014년 2월 19일

댓글:

2014년 2월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by