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

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 19 Feb 2014
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 Comments

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
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
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

Sign in to comment.

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Asked:

on 19 Feb 2014

Commented:

on 19 Feb 2014

Community Treasure Hunt

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

Start Hunting!