From: zac on 8 Jun 2010 12:54 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.
From: Michael Hosea on 8 Jun 2010 13:10 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(a)o2.pl> wrote in message news:hulsjc$phh$1(a)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.
From: zac on 8 Jun 2010 14:27 "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message <hultin$1m2$1(a)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(a)o2.pl> wrote in message > news:hulsjc$phh$1(a)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
|
Pages: 1 Prev: bar plot basic problem Next: Add a row to a uitable while program is running |