For Programmers: Free Programming Magazines  


Home > Archive > Matlab > March 2007 > How are global variables used?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How are global variables used?
How are global variables used?

2007-03-26, 7:15 pm

I' ve the following situation:

In one mfile:

code that generates an array of string
.....

ERG_Main('almacenamfiles',mFiles);

And in ERG_Main the following function

function almacenamfiles(mFiles)
for i=1:200
disp(mFiles(1));
disp(mFiles(2));
disp(mFiles(3));
end
global mFiles3
mFiles3={};
mFiles3=mFiles;

Another function

function Eye1_Load_Callback(hObject, eventdata, handles, pathname,
filename, nAge, nRX)
global mFiles3
% hObject handle to Eye1_Load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(mFiles3(1))
disp(mFiles3(2))

Is this the correct way of doing an assignation to mFiles3? And how
does a global variable correctly workż
Markus

2007-03-31, 7:09 pm

1. Better do not use global variables, this is always a source of
errors and pain.

2. If you still want to use them, read the documentation!

Markus
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com