check the code for me, please
1 view (last 30 days)
Show older comments
[EDIT: Sat May 28 23:16:33 UTC 2011 - Reformat - MKF]
code 1: to load database
function out=load_database();
% We load the database the first time we run the program.
persistent loaded;
persistent w;
if(isempty(loaded))
v=zeros(10304,400);
for i=1:40
cd(strcat('s',num2str(i)));
for j=1:10
a=imread(strcat(num2str(j),'.pgm'));
v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1);
end
cd ..
end
w=uint8(v); % Convert to unsigned 8 bit numbers to save memory.
end
loaded=1; % Set 'loaded' to aviod loading the database again.
out=w;
code 2: gui.
clear all;
close all;
clc;
while (1==1)
choice=menu('',...
'Load Database',...
'Face Recognition',...
'Exit');
if (choice == 1)
load_database;
end
if (choice == 2)
face_recognition;
end
if (choice == 3)
clear all;
clc;
main_Gui;
%close all;
return;
end
end
problem: when i click on choice 1, i'm not able to load the database but when i click on choice 2, i am able to do the recognition. please help me out.
3 Comments
Voss
on 14 Mar 2024
@maryam afarin: Please ask a new question by following the link: https://www.mathworks.com/matlabcentral/answers/questions/new/?s_tid=gn_mlc_ans_ask
Be sure to include the value of all variables people need to run your code.
Voss
on 14 Mar 2024
@maryam afarin: Anyway, you were trying to use rho, A, Z, and teilchenname before they were defined, so I moved some lines around, and you were referring to teilchenname in one place I think you meant to refer to teilchen. Try this:
% Definition von Konstanten und Variablen
Me_c2 = 0.511; % Ruheenergie des Elektrons in MeV
Pi = 3.14; % Kreiszahl
u = 1.66 * 10^-27; % kg
epsilon_0 = 8.854187817e-12; % Elektrische Feldkonstante (in C²/J.m)
e = 1.602176634e-19; % Elementarladung (in C)
% Frage den Benutzer nach dem Teilchen und Material
teilchen = input('Ist das Teilchen Alpha oder Beta? ', 's');
material = input('In welchem Material befindet sich das Teilchen? (Blei, Eisen, Beton, Stahl, PVC, Aluminium) ', 's');
teilchenname = input('Welchen Namen hat das Teilchen? ', 's');
% Definiere die Dichte, Ordnungszahl und Molare Masse basierend auf dem ausgewählten Material
switch material
case 'Blei'
rho = 11.3 * 10^3; % Dichte in kg/m³
Z = 82; % Ordnungszahl von Blei
A = 207.2; % Molare Masse des Absorbermaterials in g/mol
case 'Eisen'
rho = 7.87 * 10^3; % Dichte in kg/m³
Z = 26; % Ordnungszahl von Eisen
A = 55.845; % Molare Masse des Absorbermaterials in g/mol
case 'Beton'
rho = 2.3 * 10^3; % Dichte in kg/m³
Z = 11; % Angenommene durchschnittliche Ordnungszahl für Beton
A = 28.05; % Angenommene durchschnittliche molare Masse für Beton in g/mol
case 'Stahl'
rho = 7.85 * 10^3; % Dichte in kg/m³
Z = 26; % Ordnungszahl von Stahl (angenommen ähnlich wie Eisen)
A = 55.845; % Molare Masse des Absorbermaterials in g/mol (angenommen ähnlich wie Eisen)
case 'PVC'
rho = 1.38 * 10^3; % Dichte in kg/m³
Z = 17; % Ordnungszahl von PVC (angenommen Chlor)
A = 35.453; % Molare Masse des Absorbermaterials in g/mol (angenommen Chlor)
case 'Aluminium'
rho = 2.7 * 10^3; % Dichte in kg/m³
Z = 13; % Ordnungszahl von Aluminium
A = 26.982; % Molare Masse des Absorbermaterials in g/mol
otherwise
error('Ungültige Eingabe für das Material.');
end
% Elektronendichte des Materials (pro m^3)
n = Z/A * rho/u;
% Mittlere Ionisationsenergie nach der Auswahl des Materials
I = 9.76 * Z * 1e-6; % Korrektur: Mittlere Ionisationsenergie in MeV
% Ladungszahl des Teilchens festlegen
if strcmpi(teilchen, 'Alpha')
z = 2;
else
z = -1;
end
% Definition der Funktionen für beta und dEdx(E) in MeV/m
beta_func = @(E) sqrt(1 - (Me_c2 ./ (E + Me_c2)).^2);
dEdx_func = @(E) (39*10^24)*(4 * pi * n * z^2 ./ (Me_c2 .* beta_func(E).^2)) .* (e^2 ./ (4 * pi * epsilon_0)).^2 ...
.* (log ((2 * Me_c2 * beta_func(E).^2) ./ (I * (1 - beta_func(E).^2)) - beta_func(E).^2));
% Definition von b basierend auf dem ausgewählten Teilchen
switch teilchenname
case 'AC-225'
Emax = 5.83; % Maximale Energie von AC-225 in MeV
case 'Ra-223'
Emax = 5.71; % Maximale Energie von Ra-223 in MeV
case 'I-131'
Emax = 0.192; % Maximale Energie von I-131 in MeV
case 'Lu-177'
Emax = 0.149; % Maximale Energie von Lu-177 in MeV
case 'Y-90'
Emax = 0.932; % Maximale Energie von Y-90 in MeV
case 'TC-99m'
Emax = 0.102; % Maximale Energie von TC-99m in MeV
case 'Er-169'
Emax = 0.101; % Maximale Energie von Er-169 in MeV
otherwise
error('Ungültige Eingabe für das Teilchen.');
end
% Definition der Grenzen für die Integration
a = 0; % Untere Grenze
b = Emax; % Obere Grenze
% Integration
result = integral(@(E) 1./dEdx_func(E), a, b); % Reichweite in m
% Ausgabe des Ergebnisses
disp(['Die Reichweite von ', teilchenname, ' im Material ', material, ' mit einer Energie von ', num2str(a), ' bis ', num2str(b), ' MeV beträgt ', num2str(result), ' m']);
Answers (1)
Paulo Silva
on 29 May 2011
when you do
load_database;
you are just calling the function without saving the output, I guess you should do something similar to this
out=load_database;
Also from the documentation about persistent variables:
persistent X Y Z defines X, Y, and Z as variables that are local to the function in which they are declared; yet their values are retained in memory between calls to the function. Persistent variables are similar to global variables because the MATLAB software creates permanent storage for both. They differ from global variables in that persistent variables are known only to the function in which they are declared. This prevents persistent variables from being changed by other functions or from the MATLAB command line.
Maybe you can solve your problem by changing from persistent to global variables
If you want to save the database to the workspace memory do
assignin('base', 'w', w)
3 Comments
Paulo Silva
on 29 May 2011
When you define a variable with global properties you must declare it global anywhere you wish to use it, in the workspace or a script declare it global before trying to do something with the variable, in functions declare it global also.
I believe that your problem is in the script, you need to do
global w
Paulo Silva
on 29 May 2011
You should just use the output of the load_database instead of declaring global variables, most people avoid global variables for good reasons.
See Also
Categories
Find more on Particle & Nuclear Physics 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!