Clear Filters
Clear Filters

how to convert a fichier.m to simulink blocks.?

1 view (last 30 days)
hello i have this programme and i want convert it to block simulink.
_
function U=f(TE); % U is the output current variable
% TE is the input line vector
E=TE'; % E is the input column vector
flux=E(1); % input flux
teta=E(2); % input angle modulo pi/2
global TETAS TETAX TETAY TETAXY TETAON TETAOFF TETAQ V AUP BUP ADOWN BDOWN DL
LMIN LMAX
% if the teta value is situated between 0 and TETAX then the output is computed
% as flux/Lmin since during this interval the inductance is constant
if ((0 <= teta) & (teta <= TETAX))
U=[flux/LMIN,LMIN];
end;
% using the values computed in the initialization file int.m, we obtain for this
% interval the value of the current knowing the inductance equation
if ((TETAX < teta) & (teta <= TETAY))
U=[flux/((AUP*teta)+BUP),((AUP*teta)+BUP)];
end;
if ((TETAY < teta) & (teta <= TETAXY))
U=[flux/((ADOWN*teta)+BDOWN),((ADOWN*teta)+BDOWN)];
end;
if (teta >TETAXY)
U=[flux/LMIN,LMIN];
end;_

Answers (1)

Mischa Kim
Mischa Kim on 17 Mar 2014
Edited: Mischa Kim on 17 Mar 2014
Lahssan, you can simply use a MATLAB Function block (in: Simulink library > User-Defined Functions), open the block and paste the code as is. In earlier releases the block might have been named: Embedded MATLAB Function.
If your function has more, say for example, two inputs you can use a MUX (multiplexer) block to combine them into one input. Alternatively, you could rewrite your function definition as
function U = f(flux, teta); % U is the output current variable
which will automatically generate two inputs at the block.
  3 Comments
Mischa Kim
Mischa Kim on 17 Mar 2014
Same as above. You can use a DEMUX, or, return two output arguments:
function [U1 U2] = f(flux, teta); % U is the output current variable

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!