Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matlab function simulink error

Subject: matlab function simulink error

From: mado

Date: 5 Oct, 2012 12:52:07

Message: 1 of 7

I am trying to call this m file to simulink so i created script called it mpptrackIref
this is the code

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;
then i used matlab function block in simulink and called it MPPtrackIref it gave this error message
"Function definitions are not permitted in this context".
 

Subject: matlab function simulink error

From: Steven_Lord

Date: 5 Oct, 2012 13:04:51

Message: 2 of 7



"mado " <elec_mnf@yahoo.com> wrote in message
news:k4ml5n$g88$1@newscl01ah.mathworks.com...
> I am trying to call this m file to simulink so i created script called it
> mpptrackIref this is the code
> global Iref;

Since this is the first line in the file this is a SCRIPT, not a function.

*snip*

> function y = MPPtrackIref(P)

You are not allowed to define functions with the FUNCTION keyword inside a
script. Defining anonymous functions works, but that won't help you.

> then i used matlab function block in simulink and called it MPPtrackIref
> it gave this error message
> "Function definitions are not permitted in this context".

Yes, that's correct for the reason I gave above.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: matlab function simulink error

From: mado

Date: 5 Oct, 2012 13:21:08

Message: 3 of 7

ok, i created the function and called it in script file

global Iref;
global Increment;
global Pold;
Pold=0;
Iref=4;
Increment = -1;

y = MPPtrackIref(P);
Pold = P;
y = Iref;

then i should write the name of script in the matlab fcn block , shouldn't I?
 

Subject: matlab function simulink error

From: mado

Date: 5 Oct, 2012 13:43:10

Message: 4 of 7

how to Implement the whole code inside simulink?

Subject: matlab function simulink error

From: mado

Date: 5 Oct, 2012 17:35:07

Message: 5 of 7

any suggestions ?

Subject: matlab function simulink error

From: Phil Goddard

Date: 5 Oct, 2012 18:36:08

Message: 6 of 7


> then i should write the name of script in the matlab fcn block , shouldn't I?

It's called the MATLAB Fcn block because it executes functions not scripts.
(Note there is also the Interpreted MATLAB Fcn block, but it too only runs functions not scripts.)

How is what you have here different from your previous question?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/323378

Phil.

Subject: matlab function simulink error

From: mado

Date: 5 Oct, 2012 19:01:08

Message: 7 of 7

yes, it's different embedded fnc doesn't accept this code it gives error cause it didn't accept declaration of variables before function ???

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us