check the code for me, please

조회 수: 1 (최근 30일)
Suzzie
Suzzie 2011년 5월 28일
댓글: Voss 2024년 3월 14일
[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
Voss
Voss 2024년 3월 14일
Be sure to include the value of all variables people need to run your code.
Voss
Voss 2024년 3월 14일
@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']);

댓글을 달려면 로그인하십시오.

답변 (1개)

Paulo Silva
Paulo Silva 2011년 5월 29일
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
Paulo Silva
Paulo Silva 2011년 5월 29일
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
Paulo Silva 2011년 5월 29일
You should just use the output of the load_database instead of declaring global variables, most people avoid global variables for good reasons.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by