Undefined Variables Error - Using GUIDE

3 views (last 30 days)
I'm trying to run some basic code with plotting through GUIDE, but I don't seem to be able to initialize, load data and define default variables correctly. Essentially I need to load a large dataset of 3,000x3,000 arrays (MCNPdata), then selects which one to use, then modifies with multipliers and plots the resulting array as a mesh or image.
Here are the errors I'm getting: Undefined function or variable 'detector_type'.
Error in DoseMapperGUI>runmapper_Callback (line 286) if detector_type==1
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in DoseMapperGUI (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)DoseMapperGUI('runmapper_Callback',hObject,eventdata,guidata(hObject))
Error using drawnow Error while evaluating uicontrol Callback
Here's the code:
% --- 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
load('MCNPdata.mat');
% 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.
STstr = get(handles.source_type, 'String');
STval = get(source,'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
% 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)
SSstr = get(handles.source_strength, 'String');
SSval = get(source,'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
% 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)
DTstr = get(handles.detector_type, 'String');
DTval = get(source,'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
% 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)
Scanstr = get(handles.scan_speed, 'String');
Scanval = get(source,'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
% 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)
SHstr = get(handles.scan_height, 'String');
SHval = get(source,'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
% 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 button press in plot_imagesc.
function plot_imagesc_Callback(hObject, eventdata, handles)
% hObject handle to plot_imagesc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imagesc(PoissonMesh);figure(gcf);colormap(hot);
% --- Executes on button press in plot_mesh.
function plot_mesh_Callback(hObject, eventdata, handles)
% hObject handle to plot_mesh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mesh(PoissonMesh);figure(gcf);
% --- 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)
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

Accepted Answer

Walter Roberson
Walter Roberson on 27 Nov 2012
In some of your callbacks, you set a local variable named "detector_type". That local variable vanishes as soon as the routine returns. You need to store that value somewhere in order to retrieve it later. see http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
Also you are not initializing the String for handles.detector_type properly. Your detector_type_Callback function implies that your detector_type object is a uicontrol of style popup or listbox, in which case you need to set the String property for it to hold all of the possibilities. Alternately if you already did that when you created the object, then what you want to set is not the String property but rather the Value property, to 1, so that the first string is selected.
I would suggest that probably what you want is to have no detector_type_Callback callback, and that you want to initialize handles.detector_type Value to 1, and then each time you want to know which detector type is active, you get() the Value property of handles.detector_type

More Answers (2)

Babak
Babak on 27 Nov 2012
Before that line, where gives you the error, line # 286, add this line:
detector_type = handles.detector_type;
Please note that, the variable detector_type is not defined in the new function where you are trying to check, if detector_type==1 Therefore, you need to define it and getting it from the handles structure by
...
detector_type = handles.detector_type;
if detector_type==1
...
  1 Comment
Walter Roberson
Walter Roberson on 27 Nov 2012
No, handles.dector_type is a handle graphics handle of a uicontrol of style popup or listbox.

Sign in to comment.


Ed
Ed on 30 Nov 2012
Thanks everyone for the advice - I've only had a chance to peck at it a bit since then. I was getting errors for the 'Value' field not being defined, so I just took those out and tried to run the switch case on 'String'. I am no longer getting errors on those, but now the issue seems to be that the global variables I need to load initially aren't accessible.
Warnings: Undefined function or variable 'HeightMesh100'.
Error in DoseMapperGUI>runmapper_Callback (line 246) HeightMesh=HeightMesh100;
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in DoseMapperGUI (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)DoseMapperGUI('runmapper_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Here's my updated code:
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
load('MCNPdata.mat');
% 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)
STstr = get(handles.source_type, 'String');
% STval = get(source,'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(source,'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(source,'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(source,'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(source,'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

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!