undefine variable.

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

undefine variable.

astie darmayantie

Here i have 2 .m file which are connected. because the first .m file will call for another function in the second .m file.
So here's the mechanism i call a function in the first .m and the first .m will call another function listed in the second .m file to complete the calculation.
The problem is the second .m file can not read the variabel i have defined in the first .m :(
and keep having these error

% here i call a function from the first .m file
[edgelist, labelededgeim]=edgelink(edgeim,10);

warning: nested functions are coerced into subfunctions in file /usr/share/octave/3.6.2/m/image/cleanedgelist.m
error: `edgelist' undefined near line 310 column 17
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 310, column 5
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 99, column 61
error:   /usr/share/octave/3.6.2/m/image/edgelink.m at line 128, column 18


i already attach the .m file. i got confused because these code works very well on matlab.

Thankyou


--
Regards,


Astie Darmayantie


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave

cleanedgelist.m (18K) Download Attachment
edgelink.m (18K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: undefine variable.

Laurent Hoeltgen
Hi,

2012/8/2 astie darmayantie <[hidden email]>

Here i have 2 .m file which are connected. because the first .m file will call for another function in the second .m file.
So here's the mechanism i call a function in the first .m and the first .m will call another function listed in the second .m file to complete the calculation.
The problem is the second .m file can not read the variabel i have defined in the first .m :(
and keep having these error

% here i call a function from the first .m file
[edgelist, labelededgeim]=edgelink(edgeim,10);

warning: nested functions are coerced into subfunctions in file /usr/share/octave/3.6.2/m/image/cleanedgelist.m
error: `edgelist' undefined near line 310 column 17
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 310, column 5
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 99, column 61
error:   /usr/share/octave/3.6.2/m/image/edgelink.m at line 128, column 18


i already attach the .m file. i got confused because these code works very well on matlab.

Thankyou


--
Regards,


Astie Darmayantie


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave


If you want to use a variable defined within a function and this variable was defined somewhere else, you have to pass it as an argument to the function. This is a problem with the scope of your variables.
Btw, are you sure that this code really works in Matlab? To my knowledge this should also fail in Matlab.

Regards,
Laurent

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: undefine variable.

astie darmayantie
Yes, could you give me the example?
Of passing the variables? Because I tried but all I get is error :(
Yes already tried in matlab twice and works perfectly. That's why I am confused.
Sent from my BlackBerry®
powered by Sinyal Kuat INDOSAT

From: Hoeltgen Laurent <[hidden email]>
Date: Thu, 2 Aug 2012 09:03:16 +0200
To: astie darmayantie<[hidden email]>
Subject: Re: undefine variable.

Hi,

2012/8/2 astie darmayantie <[hidden email]>

Here i have 2 .m file which are connected. because the first .m file will call for another function in the second .m file.
So here's the mechanism i call a function in the first .m and the first .m will call another function listed in the second .m file to complete the calculation.
The problem is the second .m file can not read the variabel i have defined in the first .m :(
and keep having these error

% here i call a function from the first .m file
[edgelist, labelededgeim]=edgelink(edgeim,10);

warning: nested functions are coerced into subfunctions in file /usr/share/octave/3.6.2/m/image/cleanedgelist.m
error: `edgelist' undefined near line 310 column 17
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 310, column 5
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 99, column 61
error:   /usr/share/octave/3.6.2/m/image/edgelink.m at line 128, column 18


i already attach the .m file. i got confused because these code works very well on matlab.

Thankyou


--
Regards,


Astie Darmayantie


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave


If you want to use a variable defined within a function and this variable was defined somewhere else, you have to pass it as an argument to the function. This is a problem with the scope of your variables.
Btw, are you sure that this code really works in Matlab? To my knowledge this should also fail in Matlab.

Regards,
Laurent

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: undefine variable.

Laurent Hoeltgen
Hi,

2012/8/2 <[hidden email]>
Yes, could you give me the example?
Of passing the variables? Because I tried but all I get is error :(
Yes already tried in matlab twice and works perfectly. That's why I am confused.
Sent from my BlackBerry®
powered by Sinyal Kuat INDOSAT

From: Hoeltgen Laurent <[hidden email]>
Date: Thu, 2 Aug 2012 09:03:16 +0200
To: astie darmayantie<[hidden email]>
Subject: Re: undefine variable.

Hi,

2012/8/2 astie darmayantie <[hidden email]>

Here i have 2 .m file which are connected. because the first .m file will call for another function in the second .m file.
So here's the mechanism i call a function in the first .m and the first .m will call another function listed in the second .m file to complete the calculation.
The problem is the second .m file can not read the variabel i have defined in the first .m :(
and keep having these error

% here i call a function from the first .m file
[edgelist, labelededgeim]=edgelink(edgeim,10);

warning: nested functions are coerced into subfunctions in file /usr/share/octave/3.6.2/m/image/cleanedgelist.m
error: `edgelist' undefined near line 310 column 17
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 310, column 5
error:   /usr/share/octave/3.6.2/m/image/cleanedgelist.m at line 99, column 61
error:   /usr/share/octave/3.6.2/m/image/edgelink.m at line 128, column 18


i already attach the .m file. i got confused because these code works very well on matlab.

Thankyou


--
Regards,


Astie Darmayantie


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave


If you want to use a variable defined within a function and this variable was defined somewhere else, you have to pass it as an argument to the function. This is a problem with the scope of your variables.
Btw, are you sure that this code really works in Matlab? To my knowledge this should also fail in Matlab.

Regards,
Laurent

I had a closer look at the code. It contains function definitions inside function definitions. As far as I know, Matlab and octave handle the scope of variables w.r.t. to these functions differently. In Matlab they inherit the workspace from the parent function while in octave they don't. This is the reason why your code works in Matlab but not in octave. To remedy the problem, you would have to add all the required variables as arguments to the functions. This is gonna be quite some work. Some variables are declared global, others are passed explicitly and then there are those that are used inside the functions but not passed as arguments. In my opinion, this code is a mess. I really prefer the way how octave handles the scope of variables because it prevents people to write this kind of code.

Btw I couldn't run your code as there seem to be missing functions (i.e. findendsjunctions). So there might be some further issues with it.

Regards,
Laurent

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: undefine variable.

Carnë Draug-2
In reply to this post by astie darmayantie
On 2 August 2012 08:06,  <[hidden email]> wrote:
> Yes, could you give me the example?
> Of passing the variables? Because I tried but all I get is error :(
> Yes already tried in matlab twice and works perfectly. That's why I am
> confused.

See http://wiki.octave.org/FAQ#Nested_Functions for an example what we
mean. "The authors of Octave consider the nested function scoping
rules of Matlab to be more problems than they are worth as they
introduce difficult to find bugs as inadvertently modifying a variable
in a nested function that is also used in the parent is particularly
easy for those not attentive to detail."

Carnë
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: undefine variable.

astie darmayantie
Thank you for your information :)

2012/8/2 Carnë Draug <[hidden email]>
On 2 August 2012 08:06,  <[hidden email]> wrote:
> Yes, could you give me the example?
> Of passing the variables? Because I tried but all I get is error :(
> Yes already tried in matlab twice and works perfectly. That's why I am
> confused.

See http://wiki.octave.org/FAQ#Nested_Functions for an example what we
mean. "The authors of Octave consider the nested function scoping
rules of Matlab to be more problems than they are worth as they
introduce difficult to find bugs as inadvertently modifying a variable
in a nested function that is also used in the parent is particularly
easy for those not attentive to detail."

Carnë



--
Regards,


Astie Darmayantie


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave