From: gudny on 30 Apr 2010 05:36 Hello everyone, I have a very strange bug in my program. Basically, I have a function that creates nodes, giving each of them a new number. The current node is the one with the highest counter at each time. The counter is a persistent variable withing the function (at first I had it global, in an attempt to fix the error I changed it into a persistent variable- which didn't help). The problem is that sometimes, the parent has a higher counter then the newest child! Here is the pseodocode: function [] = ask(parent_nr....) persistent counter node_nr = counter; nodes(node_nr) = parent_nr; if ~(parent_nr<node_nr) parent_nr end if not certain ask(node_nr, ...) end What is even stranger, is that if I debug and have a breakpoint in the if loop, in front of parent_nr, the error does not occur. It only occurs, when there is no breakpoint. The debugging, seems to effect how the program is run, it is very strange. I hope someone has an idea what might be going on, or how I can get around it. cheers, Gudny
From: us on 30 Apr 2010 05:44 gudny <gudnyg(a)gmail.com> wrote in message <187fd61c-9f27-4d6c-a806-22ee4d0d5bcf(a)d39g2000yqa.googlegroups.com>... > Hello everyone, > I have a very strange bug in my program. Basically, I have a function > that creates nodes, giving each of them a new number. The current node > is the one with the highest counter at each time. The counter is a > persistent variable withing the function (at first I had it global, in > an attempt to fix the error I changed it into a persistent variable- > which didn't help). > The problem is that sometimes, the parent has a higher counter then > the newest child! Here is the pseodocode: > > function [] = ask(parent_nr....) > persistent counter > node_nr = counter; > nodes(node_nr) = parent_nr; > if ~(parent_nr<node_nr) > parent_nr > end > if not certain > ask(node_nr, ...) > end > > What is even stranger, is that if I debug and have a breakpoint in the > if loop, in front of parent_nr, the error does not occur. It only > occurs, when there is no breakpoint. The debugging, seems to effect > how the program is run, it is very strange. I hope someone has an idea > what might be going on, or how I can get around it. > cheers, > Gudny what happens if - instead of setting break points - you put a disp(counter) in your code(?)... us
From: gudny on 6 May 2010 05:38 On Apr 30, 11:44 am, "us " <u...(a)neurol.unizh.ch> wrote: > gudny <gud...(a)gmail.com> wrote in message <187fd61c-9f27-4d6c-a806-22ee4d0d5...(a)d39g2000yqa.googlegroups.com>... > > Hello everyone, > > I have a very strange bug in my program. Basically, I have a function > > that creates nodes, giving each of them a new number. The current node > > is the one with the highest counter at each time. The counter is a > > persistent variable withing the function (at first I had it global, in > > an attempt to fix the error I changed it into a persistent variable- > > which didn't help). > > The problem is that sometimes, the parent has a higher counter then > > the newest child! Here is the pseodocode: > > > function [] = ask(parent_nr....) > > persistent counter > > node_nr = counter; > > nodes(node_nr) = parent_nr; > > if ~(parent_nr<node_nr) > > parent_nr > > end > > if not certain > > ask(node_nr, ...) > > end > > > What is even stranger, is that if I debug and have a breakpoint in the > > if loop, in front of parent_nr, the error does not occur. It only > > occurs, when there is no breakpoint. The debugging, seems to effect > > how the program is run, it is very strange. I hope someone has an idea > > what might be going on, or how I can get around it. > > cheers, > > Gudny > > what happens if - instead of setting break points - you put a > > disp(counter) > > in your code(?)... > > us hi sorry, I didn't see the answer. Yes, that also makes the problem disappear. That is what I did in the end, I added a display statement within the for loop that checks that the parent has a lower counter than the child. I find this very disturbing though, and think I will change my code, so that instead of counting nodes, I will work with node objects. thank you very much for your answer.
|
Pages: 1 Prev: bode/nyquist plot from a matrix with complex numbers Next: Failure starting Matlab |