From: Adam Chapman on 8 Aug 2010 07:37 Hi, I have set up a large number of global variables. These variables conatin data loaded from .mat files. I need to use them in another function that is called many times, and making them global saves loading them inside the funtion that uses them over and over. However, in the function one of the variables is being cleared, so its value is "[ ]". I have no idea why this would happen, as there is no code to remove elements of that variable. I only use the data as a lookup table in 2D interpolation
From: Adam Chapman on 8 Aug 2010 07:41 On Aug 8, 12:37 pm, Adam Chapman <adamchapman1...(a)hotmail.co.uk> wrote: > Hi, > > I have set up a large number of global variables. > > These variables conatin data loaded from .mat files. I need to use > them in another function that is called many times, and making them > global saves loading them inside the funtion that uses them over and > over. > > However, in the function one of the variables is being cleared, so its > value is "[ ]". > > I have no idea why this would happen, as there is no code to remove > elements of that variable. I only use the data as a lookup table in 2D > interpolation it seems after the load command: >>load data.mat the data is loaded in perfectly. then after the "global" command: global var1 var2 var3... the variable is empty! how??
From: Adam Chapman on 8 Aug 2010 08:08 On Aug 8, 12:41 pm, Adam Chapman <adamchapman1...(a)hotmail.co.uk> wrote: > On Aug 8, 12:37 pm, Adam Chapman <adamchapman1...(a)hotmail.co.uk> > wrote: > > > Hi, > > > I have set up a large number of global variables. > > > These variables conatin data loaded from .mat files. I need to use > > them in another function that is called many times, and making them > > global saves loading them inside the funtion that uses them over and > > over. > > > However, in the function one of the variables is being cleared, so its > > value is "[ ]". > > > I have no idea why this would happen, as there is no code to remove > > elements of that variable. I only use the data as a lookup table in 2D > > interpolation > > it seems after the load command:>>load data.mat > > the data is loaded in perfectly. > > then after the "global" command: > global var1 var2 var3... > the variable is empty! > > how?? Can you set too many global variables? I have 26 variables from 5 .mat files, in total they use 19.5 megabytes. I can't think that would be a problem since i have 4GB RAm
From: Adam Chapman on 8 Aug 2010 08:22 On Aug 8, 1:08 pm, Adam Chapman <adamchapman1...(a)hotmail.co.uk> wrote: > On Aug 8, 12:41 pm, Adam Chapman <adamchapman1...(a)hotmail.co.uk> > wrote: > > > > > > > On Aug 8, 12:37 pm, Adam Chapman <adamchapman1...(a)hotmail.co.uk> > > wrote: > > > > Hi, > > > > I have set up a large number of global variables. > > > > These variables conatin data loaded from .mat files. I need to use > > > them in another function that is called many times, and making them > > > global saves loading them inside the funtion that uses them over and > > > over. > > > > However, in the function one of the variables is being cleared, so its > > > value is "[ ]". > > > > I have no idea why this would happen, as there is no code to remove > > > elements of that variable. I only use the data as a lookup table in 2D > > > interpolation > > > it seems after the load command:>>load data.mat > > > the data is loaded in perfectly. > > > then after the "global" command: > > global var1 var2 var3... > > the variable is empty! > > > how?? > > Can you set too many global variables? > I have 26 variables from 5 .mat files, in total they use 19.5 > megabytes. > > I can't think that would be a problem since i have 4GB RAm- Hide quoted text - > > - Show quoted text - God knows what happened, but turning it off and on again worked lol!
From: Jan Simon on 8 Aug 2010 14:50 Dear Adam, > God knows what happened, but turning it off and on again worked lol! I have the strong impression, that God does not know, what happend. What was "it", that you turned off and on? It is a general problem of GLOBAL variables, that they impede debugging quite seriously. E.g.: x = 1; load File.mat disp(x) If File.mat contains the variable x, the original x is overwritten. If x is a GLOBAL, this can happen even in all functions and subfunctions. It is a magnitude safer to collect all GLOBALs in one struct, e.g. called "adamsGlobal", and use an output for the LOAD command *ever*: x = 1; M = load('File.mat') adamsGlobal.Data = M.Data; BTW, I've seen 3 toolboxes creating a GLOBAL called "myGlobal", so I'd suggest to avoid this name. But if you have your data collected in a single struct, it is easy and fast to forward this struct as input to all functions and you do not need the susceptible GLOBALs at all. This would by a simple but efficient step towards a robust programming technique. Kind regards, Jan
|
Pages: 1 Prev: Figure orientation changes when I save the figure Next: Content based image retrieval |