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:
Initial value of Embedded Matlab Function

Subject: Initial value of Embedded Matlab Function

From: zac

Date: 8 Jun, 2010 16:54:04

Message: 1 of 3

Hello,

i have a trouble with initial value of variable in Embedded Matlab Function.
I've found similar topic but i the errors still appear.
http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/249084


My code:

function [xx, cs1,number_point] = fcn(x,xr)
%#eml

persistent ini
if isempty(ini)
    ini = 1;
    number_point = 1;
end
    
ex = xr - x;

if (abs(ex) > 0.01)
    xx = ex;
    cs1 = 1;
else
    xx = 0;
    cs1 = 0;
    number_point = number_point + 1;
end

and i have 4 errors:
1.Variable 'number_point' is undefined on some execution paths.
2.Errors occurred during parsing of Embedded MATLAB function 'Embedded MATLAB
Function'
3.Coder Error
4.Model Error

I also know from similar topic that persistent variable can't be an output.
But i dont know how to change it.
Thanks for advice.
Regards,
ZaC.

Subject: Initial value of Embedded Matlab Function

From: Michael Hosea

Date: 8 Jun, 2010 17:10:47

Message: 2 of 3

Declare number_point persistent, rename the third output, and copy the value
of number_point to the output variable before returning:

function [xx, cs1,np] = fcn(x,xr)
%#eml

persistent ini number_point
if isempty(ini)
   ini = 1;
   number_point = 1;
end

ex = xr - x;

if (abs(ex) > 0.01)
   xx = ex;
   cs1 = 1;
else
   xx = 0;
   cs1 = 0;
   number_point = number_point + 1;
end
np = number_point;



"zac " <sony_1000@o2.pl> wrote in message
news:hulsjc$phh$1@fred.mathworks.com...
> Hello,
>
> i have a trouble with initial value of variable in Embedded Matlab
> Function.
> I've found similar topic but i the errors still appear.
> http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/249084
>
>
> My code:
>
> function [xx, cs1,number_point] = fcn(x,xr)
> %#eml
>
> persistent ini
> if isempty(ini)
> ini = 1;
> number_point = 1; end
> ex = xr - x;
>
> if (abs(ex) > 0.01) xx = ex;
> cs1 = 1;
> else
> xx = 0;
> cs1 = 0;
> number_point = number_point + 1;
> end
>
> and i have 4 errors:
> 1.Variable 'number_point' is undefined on some execution paths.
> 2.Errors occurred during parsing of Embedded MATLAB function 'Embedded
> MATLAB
> Function'
> 3.Coder Error
> 4.Model Error
>
> I also know from similar topic that persistent variable can't be an
> output.
> But i dont know how to change it.
> Thanks for advice.
> Regards,
> ZaC.

Subject: Initial value of Embedded Matlab Function

From: zac

Date: 8 Jun, 2010 18:27:22

Message: 3 of 3

"Michael Hosea" <Michael.Hosea@mathworks.com> wrote in message <hultin$1m2$1@fred.mathworks.com>...
> Declare number_point persistent, rename the third output, and copy the value
> of number_point to the output variable before returning:
>
> function [xx, cs1,np] = fcn(x,xr)
> %#eml
>
> persistent ini number_point
> if isempty(ini)
> ini = 1;
> number_point = 1;
> end
>
> ex = xr - x;
>
> if (abs(ex) > 0.01)
> xx = ex;
> cs1 = 1;
> else
> xx = 0;
> cs1 = 0;
> number_point = number_point + 1;
> end
> np = number_point;
>
>
>
> "zac " <sony_1000@o2.pl> wrote in message
> news:hulsjc$phh$1@fred.mathworks.com...
> > Hello,
> >
> > i have a trouble with initial value of variable in Embedded Matlab
> > Function.
> > I've found similar topic but i the errors still appear.
> > http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/249084
> >
> >
> > My code:
> >
> > function [xx, cs1,number_point] = fcn(x,xr)
> > %#eml
> >
> > persistent ini
> > if isempty(ini)
> > ini = 1;
> > number_point = 1; end
> > ex = xr - x;
> >
> > if (abs(ex) > 0.01) xx = ex;
> > cs1 = 1;
> > else
> > xx = 0;
> > cs1 = 0;
> > number_point = number_point + 1;
> > end
> >
> > and i have 4 errors:
> > 1.Variable 'number_point' is undefined on some execution paths.
> > 2.Errors occurred during parsing of Embedded MATLAB function 'Embedded
> > MATLAB
> > Function'
> > 3.Coder Error
> > 4.Model Error
> >
> > I also know from similar topic that persistent variable can't be an
> > output.
> > But i dont know how to change it.
> > Thanks for advice.
> > Regards,
> > ZaC.
>

Thanks a lot. Now i understand it.
Regards,
ZaC

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