필터 지우기
필터 지우기

how to embed matlab function simulink

조회 수: 7 (최근 30일)
mado
mado 2012년 10월 5일
How to call this code in simulink while running as one of it's blocks
% intialization global Iref; global Increment; global Pold; Pold=0; Iref=4; Increment = -1;
function y = MPPtrackIref(P)
global Pold; global Iref; global Increment; IrefH = 5; IrefL =0; DeltaI = .02
if (P < Pold) Increment = - Increment; end
Iref = Iref + Increment*DeltaI
end
Pold = P; y = Iref;
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 5일
What is the version of Matlab, what is your error message?
Walter Roberson
Walter Roberson 2012년 10월 9일
Please read the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 5일
You don't need to use global variables, just use constant blocks and pass them through your matlab function

추가 답변 (4개)

Kaustubha Govind
Kaustubha Govind 2012년 10월 5일
편집: Kaustubha Govind 2012년 10월 5일
As explained in this previously asked question, it appears that you need to use global variables inside MATLAB Function blocks in conjunction with Data Store Memory blocks. If you really just mean to use those global variables as persistent memory, you should try:
function y = MPPtrackIref(P)
persistent Pold Iref Increment;
if isempty(Pold)
Pold=0; %initialized only once in the beginning
end
if isempty(Iref)
Iref=4; %initialized only once in the beginning
end
if isempty(Increment)
Increment = -1; %initialized only once in the beginning
end
IrefH = 5; IrefL =0; DeltaI = .02;
if (P < Pold)
Increment = - Increment;
end
Iref = Iref + Increment*DeltaI;
end
Pold = P;
y = Iref;

Julien
Julien 2012년 10월 5일
Hi, You can use the ' Matlab function ' block (found inside user-defined function library )
But this simple function can also be defined with usual simulinks block (with boolean test and unit delay blocks).
Why do you need to define your constants as global variable ?

mado
mado 2012년 10월 5일
I used matlab function but it gives me error , i can't write it in script file as it doesn't accept function and i can't write it in a function as it doesn't accept first declarations

mado
mado 2012년 10월 5일
how to pass them ??
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 5일
add a constant block and set a constant value to variable v (for example). in your m file or matlab command assign a value to your variable v

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

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by