Global Variables Warning, not Error

3 次查看(过去 30 天)
Ed
Ed 2012-12-4
I need to load a large dataset of pre-computed matrices, but I need this data to be available throughout the GUI. I load the .mat file with all my data and set each matrix/array as a global variable. However, when I run the 'runmapper' function I get these errors for all the globals:
Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable. > In DoseMapperGUI>runmapper_Callback at 234 In gui_mainfcn at 96 In DoseMapperGUI at 42 In @(hObject,eventdata)DoseMapperGUI('runmapper_Callback',hObject,eventdata,guidata(hObject))
Is there a better way to have all these large datasets available?
My code (Globals are defined near the end):
function varargout = DoseMapperGUI(varargin)
% DOSEMAPPERGUI MATLAB code for DoseMapperGUI.fig
% DOSEMAPPERGUI, by itself, creates a new DOSEMAPPERGUI or raises the existing
% singleton*.
%
% H = DOSEMAPPERGUI returns the handle to a new DOSEMAPPERGUI or the handle to
% the existing singleton*.
%
% DOSEMAPPERGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DOSEMAPPERGUI.M with the given input arguments.
%
% DOSEMAPPERGUI('Property','Value',...) creates a new DOSEMAPPERGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DoseMapperGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DoseMapperGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help DoseMapperGUI
% Last Modified by GUIDE v2.5 29-Nov-2012 14:23:05
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DoseMapperGUI_OpeningFcn, ...
'gui_OutputFcn', @DoseMapperGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before DoseMapperGUI is made visible.
function DoseMapperGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to DoseMapperGUI (see VARARGIN)
% Load MCNP Pre-Calculated Mesh Data
% MCNPdata.mat must be located in the active directory
% Choose default command line output for DoseMapperGUI
handles.output = hObject;
%set(handles.source_type,'String','Single Point-source');
% source_type = 1;
%set(handles.scan_height,'String','100ft');
% HeightMesh=HeightMesh100;
%set(handles.source_strength,'String','1Rem/hr');
% Source_Mesh=3.7E+10*3.5*HeightMesh;
%set(handles.scan_speed,'String','12knots (20fps)');
% scan_speed=1;
%set(handles.detector_type,'String','3"x3" NaI');
% detector_type=1;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DoseMapperGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DoseMapperGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in source_type.
function source_type_Callback(hObject, eventdata, handles)
% hObject handle to source_type (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Determine the selected data set.
% Hints: contents = cellstr(get(hObject,'String')) returns source_type contents as cell array
% contents{get(hObject,'Value')} returns selected item from source_type
% --- Executes during object creation, after setting all properties.
function source_type_CreateFcn(hObject, eventdata, handles)
% hObject handle to source_type (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in source_strength.
function source_strength_Callback(hObject, eventdata, handles)
% hObject handle to source_strength (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns source_strength contents as cell array
% contents{get(hObject,'Value')} returns selected item from source_strength
% --- Executes during object creation, after setting all properties.
function source_strength_CreateFcn(hObject, eventdata, handles)
% hObject handle to source_strength (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in detector_type.
function detector_type_Callback(hObject, eventdata, handles)
% hObject handle to detector_type (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns detector_type contents as cell array
% contents{get(hObject,'Value')} returns selected item from detector_type
% --- Executes during object creation, after setting all properties.
function detector_type_CreateFcn(hObject, eventdata, handles)
% hObject handle to detector_type (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in scan_speed.
function scan_speed_Callback(hObject, eventdata, handles)
% hObject handle to scan_speed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns scan_speed contents as cell array
% contents{get(hObject,'Value')} returns selected item from scan_speed
% --- Executes during object creation, after setting all properties.
function scan_speed_CreateFcn(hObject, eventdata, handles)
% hObject handle to scan_speed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in scan_height.
function scan_height_Callback(hObject, eventdata, handles)
% hObject handle to scan_height (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
% Hints: contents = cellstr(get(hObject,'String')) returns scan_height contents as cell array
% contents{get(hObject,'Value')} returns selected item from scan_height
% --- Executes during object creation, after setting all properties.
function scan_height_CreateFcn(hObject, eventdata, handles)
% hObject handle to scan_height (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in runmapper.
function runmapper_Callback(hObject, eventdata, handles)
% hObject handle to runmapper (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Load MCNP Pre-Calculated Mesh Data
% MCNPdata.mat must be located in the active directory
load('MCNPdata.mat');
global HeightMesh100;
global HeightMesh300;
global HeightMesh500;
global HeightMesh700;
global HeightMesh1000;
global Interp_Distance;
global Interp_MCNP_Flux;
STstr = get(handles.source_type, 'String');
STval = get(handles.source_type,'Value');
% Set current data to the selected data set.
switch STstr{STval};
case 'Single Point-source'
source_type=1;
case 'Multiple Point-sources'
source_type=2;
case 'Gaussian Distribution'
source_type=3;
end
SHstr = get(handles.scan_height, 'String');
SHval = get(handles.scan_height,'Value');
% Set current data to the selected data set.
switch SHstr{SHval};
case '100ft'
HeightMesh=HeightMesh100;
case '300ft'
HeightMesh=HeightMesh300;
case '500ft'
HeightMesh=HeightMesh500;
case '700ft'
HeightMesh=HeightMesh700;
case '1,000ft'
HeightMesh=HeightMesh1000;
end
SSstr = get(handles.source_strength, 'String');
SSval = get(handles.source_strength,'Value');
% Set current data to the selected data set.
switch SSstr{SSval};
case '1Rem/hr'
Source_Mesh=3.7E+10*3.5*HeightMesh;
case '3Rem/hr'
Source_Mesh=3.7E+10*10*HeightMesh;
case '5Rem/hr'
Source_Mesh=3.7E+10*17*HeightMesh;
end
Scanstr = get(handles.scan_speed, 'String');
Scanval = get(handles.scan_speed,'Value');
% Set current data to the selected data set.
switch Scanstr{Scanval};
case '12knots (20fps)'
scan_speed=1;
case '30knots (50fps)'
scan_speed=2;
case '59knots (100fps)'
scan_speed=3;
case '89knots (150fps)'
scan_speed=4;
case '118knots (200fps)'
scan_speed=5;
end
DTstr = get(handles.detector_type, 'String');
DTval = get(handles.detector_type,'Value');
% Set current data to the selected data set.
switch DTstr{DTval};
case '3"x3" NaI'
detector_type=1;
case '2"x2" NaI'
detector_type=2;
case '1"x1" NaI'
detector_type=3;
case 'GM Tube'
detector_type=4;
end
if detector_type==1
DetEff=0.3;
DetSA=4*pi*(1.5*2.54)^2;
DetScale=DetEff*DetSA;
DetBG=200;
elseif detector_type==2
DetEff=0.25;
DetSA=4*pi*(1*2.54)^2;
DetScale=DetEff*DetSA;
DetBG=100;
elseif detector_type==3
DetEff=0.2;
DetSA=4*pi*(.5*2.54)^2;
DetScale=DetEff*DetSA;
DetBG=30;
elseif detector_type==4
DetEff=0.02;
DetSA=3;
DetScale=DetEff*DetSA;
DetBG=1;
end
NetCPSMesh=Source_Mesh*DetScale;
if scan_speed==1
mesh=3000/20;
gridspace=20;
elseif scan_speed==2
mesh=3000/50;
gridspace=50;
elseif scan_speed==3
mesh=3000/100;
gridspace=100;
elseif scan_speed==4
mesh=3000/150;
gridspace=150;
elseif scan_speed==5
mesh=3000/200;
gridspace=200;
end
IdealScanMesh=zeros(mesh,mesh);
for i=1:1:mesh
for j=1:1:mesh
amax=i*gridspace;
amin=amax-gridspace+1;
b=(j*gridspace)-(gridspace/2);
CPSIntegral=NetCPSMesh(amin:amax,b);
Counts=trapz(CPSIntegral/gridspace);
IdealScanMesh(i,j)=Counts;
end
end
PoissonMesh=zeros(mesh,mesh);
for i=1:1:mesh
for j=1:1:mesh
count=IdealScanMesh(i,j)+DetBG;
RealCount=poissrnd(count);
PoissonMesh(i,j)=RealCount;
end
end
imagesc(PoissonMesh);

回答(2 个)

John Petersen
John Petersen 2012-12-4
I use setappdata(), getappdata() functions to access variables throughout my GUI.

Walter Roberson
Walter Roberson 2012-12-5
The values are defined in your
load('MCNPdata.mat');
and then you declare them global. The global calls need to be before the values are loaded.
I notice you do not use the variables in any other routine. There is no point then in declaring them global. Not unless you move the load() out of the run routine and initialize the variables once before hand, global'ing the existing values into existence in the run routine.

类别

Help CenterFile Exchange 中查找有关 Maintain or Transition figure-Based Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by